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.
2 parents 33dc6e9 + 6305af0 commit 15182a4Copy full SHA for 15182a4
1 file changed
number-of-1-bits/ppxyn1.py
@@ -1,5 +1,7 @@
1
# idea: -
2
3
+# Ans 1
4
+# Time Complexity: O(N) ?
5
from collections import Counter
6
class Solution:
7
def hammingWeight(self, n: int) -> int:
@@ -8,3 +10,13 @@ def hammingWeight(self, n: int) -> int:
8
10
9
11
12
13
+# Ans 2
14
+# Time Complexity: O(N)
15
+class Solution:
16
+ def hammingWeight(self, n: int) -> int:
17
+ cnt = 0
18
+ while n:
19
+ cnt += n & 1 # check current bit
20
+ n >>= 1 # move to next bit
21
+ return cnt
22
+
0 commit comments