Skip to content

Commit 428e617

Browse files
author
Jeongwon Na
committed
counting bits solution
1 parent 699a5ba commit 428e617

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

counting-bits/njngwn.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public int[] countBits(int n) {
3+
int[] bitCountArr = new int[n+1];
4+
5+
for (int i = 1; i <= n; ++i) {
6+
bitCountArr[i] = bitCountArr[i/2] + (i & 1);
7+
}
8+
9+
return bitCountArr;
10+
}
11+
}

0 commit comments

Comments
 (0)