Skip to content

Commit 65708f6

Browse files
committed
feat: Add Number of 1 bits Solution #232
문제 링크: https://leetcode.com/problems/number-of-1-bits/description/
1 parent 5409217 commit 65708f6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

number-of-1-bits/river20s.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +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

0 commit comments

Comments
 (0)