One Line Bit Shifting Solution


  • 0
    R
    class Solution(object):
        def hammingWeight(self, n):
            """
            :type n: int
            :rtype: int
            """
            return sum([((1 << i) & n) >> i for i in xrange(32)])
    
    

Log in to reply
 

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