mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 00:25:22 +08:00
10 lines
156 B
Go
10 lines
156 B
Go
package leetcode
|
|
|
|
func countBits(num int) []int {
|
|
bits := make([]int, num+1)
|
|
for i := 1; i <= num; i++ {
|
|
bits[i] += bits[i&(i-1)] + 1
|
|
}
|
|
return bits
|
|
}
|