Skip to content

Commit 61b0d76

Browse files
committed
338. Counting Bits
1 parent 5c71acf commit 61b0d76

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Counting Bits/kata.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package kata
2+
3+
func countBits(n int) []int {
4+
o := make([]int, n+1)
5+
for k := 0; k <= n; k++ {
6+
var num = k
7+
var count int
8+
for num > 0 {
9+
count += num & 1
10+
num >>= 1
11+
}
12+
o[k] = count
13+
}
14+
return o
15+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy