LeetCode: Counting Bits

f[i] = f[i/2] + i%2;

1 public class Solution {
2     public int[] countBits(int num) {
3         int[] ans = new int[num+1];
4         for (int i = 0; i < ans.length; i++) {
5             ans[i] = ans[i / 2] + i % 2;
6         }
7         return ans;
8     }
9 }
原文地址:https://www.cnblogs.com/yingzhongwen/p/6086887.html