Skip to content

Commit

Permalink
Create 191-Number-of-1-Bits.py
Browse files Browse the repository at this point in the history
  • Loading branch information
neetcode-gh authored Dec 26, 2021
1 parent 76c8cfb commit de87b63
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions 191-Number-of-1-Bits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Solution:
def hammingWeight(self, n: int) -> int:
res = 0
while n:
n &= (n - 1)
res += 1
return res

0 comments on commit de87b63

Please sign in to comment.