10 lines
198 B
Python
10 lines
198 B
Python
|
class Solution:
|
||
|
def hammingWeight(self, n: int) -> int:
|
||
|
count = 0
|
||
|
|
||
|
while n:
|
||
|
count += 1 if n & 1 == 1 else 0
|
||
|
n >>= 1
|
||
|
|
||
|
return count
|