338. Counting Bits比特位计数

zhfang
class Solution {
    public int[] countBits(int num) {
        int[] dp = new int[num+1];
        dp[0] = 0;
        for(int i = 1; i <= num; i++) {
            dp[i] = dp[i/2] + i%2;
        }
        return dp;
    }
}
阅读 86
4 声望
1 粉丝
0 条评论
4 声望
1 粉丝
宣传栏