A simple python solution


  • 0
    L
    class Solution:
    # @param n, an integer
    # @return an integer
    def hammingWeight(self, n):
        results = 0
        for i in range(32):
            results +=  ((n>>i)&1)
        return results

Log in to reply
 

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