HTMLify
LeetCode - Counting Bits - Go
Views: 337 | Author: abh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | func one_count(n int) int { var count int for ;n!=0; { if n%2==1 { count++ } n /= 2 } return count } func countBits(n int) []int { var ans []int for i:=0;i<=n;i++ { ans = append(ans, one_count(i)) } return ans } |