Skip to content

Latest commit

 

History

History
32 lines (23 loc) · 413 Bytes

191.md

File metadata and controls

32 lines (23 loc) · 413 Bytes

Number of 1 Bits

Description

link


Solution

See Code


Code

O(n)

class Solution(object):
    def hammingWeight(self, n):
        """
        :type n: int
        :rtype: int
        """
        res = 0
        for _ in range(32):
            if n & 1:
                res += 1
            n >>= 1
        return res