Number of 1 Bits Solutions in GoNumber 191Difficulty EasyAcceptance 50.0%Link LeetCodeOther languages C++SolutionsGo solution by halfrost/LeetCode-Gopackage leetcode import "math/bits" // 解法一func hammingWeight(num uint32) int { return bits.OnesCount(uint(num))} // 解法二func hammingWeight1(num uint32) int { count := 0 for num != 0 { num = num & (num - 1) count++ } return count}package leetcode import "math/bits" // 解法一 func hammingWeight(num uint32) int { return bits.OnesCount(uint(num)) } // 解法二 func hammingWeight1(num uint32) int { count := 0 for num != 0 { num = num & (num - 1) count++ } return count }