Skip to content

Commit 801c4d0

Browse files
author
leeli
committed
添加题目
1 parent 64991ce commit 801c4d0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

solution/go/0338-2/counting-bits.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package problem0338
2+
3+
func countBits(num int) []int {
4+
ans, i, b := make([]int, num+1), 0, 1
5+
6+
for b <= num {
7+
for i < b && i + b <= num {
8+
ans[i+b] = ans[i] + 1
9+
i++
10+
}
11+
i = 0
12+
b <<= 1
13+
}
14+
return ans
15+
}

0 commit comments

Comments
 (0)