cs: add “338. Counting Bits”
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
3ed4e64b20
commit
d06468acfe
1 changed files with 11 additions and 0 deletions
11
cs/counting-bits.cs
Normal file
11
cs/counting-bits.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue