mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-10 00:09:06 +01:00
12 lines
235 B
C#
12 lines
235 B
C#
|
public class Solution {
|
||
|
public int[] CountBits(int n) {
|
||
|
var counters = new int[n + 1];
|
||
|
|
||
|
for (var i = 1; i <= n; ++i) {
|
||
|
counters[i] = counters[i >> 1] + i % 2;
|
||
|
}
|
||
|
|
||
|
return counters;
|
||
|
}
|
||
|
}
|