题目地址:
https://leetcode.com/problems/counting-bits/
一道水题。。。
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] = (i & 1) + dp[i >> 1];
}
return dp;
}
}
时间复杂度。
来源:CSDN
作者:edWard的算法世界
链接:https://blog.csdn.net/qq_46105170/article/details/104097142