leetcode

Leetcode submissions
git clone git://git.laack.co/leetcode.git
Log | Files | Refs | README

number-of-1-bitsV2.py (238B)


      1 class Solution:
      2     def hammingWeight(self, n: int) -> int:
      3         return count_bits(n)
      4 
      5 
      6 def count_bits(n: int) -> int:
      7     count = 0
      8 
      9     while n != 0:
     10         if n & 1 == 1:
     11             count += 1
     12         n = n >> 1
     13 
     14     return count