cs: add “338. Counting Bits”

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2024-01-07 00:02:39 +01:00
parent 3ed4e64b20
commit d06468acfe
Signed by: mfocko
GPG key ID: 7C47D46246790496

11
cs/counting-bits.cs Normal file
View file

@ -0,0 +1,11 @@
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;
}
}