Skip to content

Commit 703cbe0

Browse files
committed
solve: number-of-1-bits
1 parent 19151db commit 703cbe0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

number-of-1-bits/Raft.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def hammingWeight(self, n: int) -> int:
3+
res = 0
4+
while n:
5+
res += n % 2
6+
n = n >> 1
7+
return res
8+
# T: logn
9+
# S: 1
10+

0 commit comments

Comments
 (0)