Skip to content

Commit 9bc84ff

Browse files
week 3: Number of 1 bits
1 parent 9f4c8a9 commit 9bc84ff

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

number-of-1-bits/prograsshopper.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+
# Time complexity: O(log n)
4+
output = 1
5+
while n > 1:
6+
remain = n % 2
7+
n = n // 2
8+
if remain == 1:
9+
output += 1
10+
return output

valid-palindrome/prograsshopper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ def isPalindrome(self, s: str) -> bool:
33
formatted_string = "".join(elem.lower() for elem in s if elem.isalnum())
44

55
# sol 1
6+
# Time complexity: O(n)
67
return formatted_string == formatted_string[::-1]
78

89
# sol 2
10+
# Time complexity: O(n)
911
left = 0
1012
right = len(formatted_string) - 1
1113
while left < right:

0 commit comments

Comments
 (0)