1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-19 09:46:57 +02:00
LeetCode/cs/counting-bits.cs
Matej Focko d06468acfe
cs: add “338. Counting Bits”
Signed-off-by: Matej Focko <mfocko@redhat.com>
2024-01-07 00:02:39 +01:00

11 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;
}
}