- https://leetcode.com/problems/counting-bits/
- time complexity : O(n * log n), logn ์ด ๋ถ๋ ์ด์ ๋ bit๋ log๋ฅผ ๋ฐ๋ผ ์๊ฐ ๊ฒฐ์ ๋๊ธฐ ๋๋ฌธ
- space complexity : O(n)
- https://algorithm.jonghoonpark.com/2024/04/23/leetcode-338
public int[] countBits(int n) {
int result[] = new int[n + 1];
for (int i = 0; i <= n; i++) {
int num = i;
int count = 0;
while (num > 0) {
count += num & 1;
num = num >> 1;
}
result[i] = count;
}
return result;
}