Skip to content

Commit 12d35cb

Browse files
committed
week 3 solutions
1 parent cd5f9f7 commit 12d35cb

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

number-of-1-bits/i-mprovising.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""
2+
Time complexity O(n)
3+
Space complexity O(1)
4+
"""
5+
6+
class Solution:
7+
def hammingWeight(self, n: int) -> int:
8+
return bin(n).count('1')
9+

valid-palindrome/i-mprovising.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
Time complexity O(n)
3+
Space complexity O(n)
4+
"""
5+
6+
class Solution:
7+
def isPalindrome(self, s: str) -> bool:
8+
# preprocessing
9+
string = [c for c in s.lower() if c.isalnum()]
10+
11+
if string == [c for c in string[::-1]]:
12+
return True
13+
return False

0 commit comments

Comments
 (0)