class Solution {
public int[] countBits(int n) {
int[] ans = new int[n + 1];
for (int i = 1; i <= n; i++) ans[i] = ans[i >> 1] + (i & 1);
return ans;
}
}
Verdict: Each value from a smaller one.
Before you submit
Edge cases and common mistakes
Test these inputs
n = 0 ([0])
Mistakes people make
Counting each number separately (O(n log n), fine but not the point).