HTMLify

LeetCode - Number of 1 Bits - Go
Views: 1 | Author: abh
func hammingWeight(n int) int {
    var w int
    for ;n!=0; {
        if n%2==1 {
            w++
            n--
        } else {
            n /= 2
        }
    }
    return w
}

Comments