We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4b09054 commit da3aad9Copy full SHA for da3aad9
1 file changed
number-of-1-bits/yuseok89.py
@@ -0,0 +1,13 @@
1
+# TC: O(logN)
2
+# SC: O(1)
3
+class Solution:
4
+ def hammingWeight(self, n: int) -> int:
5
+
6
+ cnt = 0
7
8
+ while n > 0:
9
+ cnt = cnt + (n % 2)
10
+ n //= 2
11
12
+ return cnt
13
0 commit comments