Skip to content

Commit 52e8667

Browse files
committed
Week 3: number-1-bits
1 parent 9ff7423 commit 52e8667

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

number-of-1-bits/mandel-17.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import collections
2+
3+
class Solution:
4+
def hammingWeight(self, n: int) -> int:
5+
two_digit = []
6+
while n >= 1:
7+
two_digit.append(n % 2)
8+
n = n // 2
9+
cnt_dict = collections.Counter(two_digit)
10+
return cnt_dict[1]

0 commit comments

Comments
 (0)