Skip to content

Commit eb35585

Browse files
authored
Merge pull request #2112 from WHYjun/week3
[WHYjun] WEEK 03 solutions=
2 parents 115b2b1 + 7866201 commit eb35585

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

number-of-1-bits/WHYjun.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution:
2+
def hammingWeight(self, n: int) -> int:
3+
result = 0
4+
for i in range(32):
5+
if (n >> i) & 1:
6+
result += 1
7+
return result

valid-palindrome/WHYjun.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def isPalindrome(self, s: str) -> bool:
3+
s = [c.lower() for c in s if c.isalnum()]
4+
5+
if len(s) == 1:
6+
return True
7+
8+
l, r = 0, len(s) - 1
9+
while l < r:
10+
if s[l] != s[r]:
11+
return False
12+
l += 1
13+
r -= 1
14+
return True

0 commit comments

Comments
 (0)