Skip to content

Commit c4e90ae

Browse files
committed
feat: implement hammingWeight for Number of 1 Bits
1 parent 65708f6 commit c4e90ae

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

number-of-1-bits/river20s.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
class Solution(object):
2-
def hammingWeight(self, n):
3-
"""
4-
:type n: int
5-
:rtype: int
6-
Time complexity: O(1)
7-
Space complexity: O(1)
8-
"""
9-
count = 0
10-
for _ in range(32):
11-
count += n & 1
12-
n >>= 1
13-
return count
1+
class Solution(object):
2+
def hammingWeight(self, n):
3+
"""
4+
:type n: int
5+
:rtype: int
6+
Time complexity: O(1)
7+
Space complexity: O(1)
8+
"""
9+
count = 0
10+
for _ in range(32):
11+
count += n & 1
12+
n >>= 1
13+
return count

0 commit comments

Comments
 (0)