question archive class Solution { public int[] countBits(int n) { int[] out = new int[n + 1]; for (int i = 0; i <= n; i++) { out[i] = out[i / 2] + i % 2; } return out; } }
Subject:Computer SciencePrice: Bought3
class Solution {
public int[] countBits(int n) {
int[] out = new int[n + 1];
for (int i = 0; i <= n; i++) {
out[i] = out[i / 2] + i % 2;
}
return out;
}
}