MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / countBits

Function countBits

counting_bits_338/solution.go:3–10  ·  view source on GitHub ↗
(num int)

Source from the content-addressed store, hash-verified

1package counting_bits_338
2
3func countBits(num int) []int {
4 bits := make([]int, num+1)
5 for n := 1; n <= num; n++ {
6 bits[n] = bits[n&(n-1)] + 1
7 }
8
9 return bits
10}

Callers 1

Test_countBitsFunction · 0.85

Calls

no outgoing calls

Tested by 1

Test_countBitsFunction · 0.68