Skip to content

Commit 6c34a43

Browse files
committed
Create Number of 1 Bits.py
1 parent b3e2a56 commit 6c34a43

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Number of 1 Bits.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution:
2+
def hammingWeight(self, n):
3+
weight = 0
4+
while n != 0:
5+
if n%2:
6+
weight += 1
7+
n = n >> 1
8+
return weight

0 commit comments

Comments
 (0)