C# Solution


  • 0
        public int HammingWeight(uint n) {
            int count = 0;
            
            while (n != 0)
            {
                if ((n & (~n + 1)) == 1)
                    count++;
                    
                n = n >> 1;
            }
            
            return count;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.