1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-19 17:56:55 +02:00

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