number-of-1-bits py3

This commit is contained in:
2022-04-26 02:31:01 +05:30
parent 6450ef0347
commit 846ddad820
2 changed files with 44 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
class Solution:
def hammingWeight(self, n: int) -> int:
count = 0
while n:
count += 1 if n & 1 == 1 else 0
n >>= 1
return count