Skip to content

Commit 5740518

Browse files
committed
[W4]
valid-palindrome solution
1 parent 6ef3bee commit 5740518

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

two-sum/sun912.py

Whitespace-only changes.

valid-palindrome/sun912.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution:
2+
def isPalindrome(self, s: str) -> bool:
3+
str = list(s.lower())
4+
chars = []
5+
for c in str:
6+
if (ord(c) >= ord("a") and ord(c) <= ord("z")) or (ord(c) >= ord("0") and ord(c) <= ord("9")):
7+
chars.append(c)
8+
9+
for i in range(len(chars)//2):
10+
11+
if len(c)%2 == 0:
12+
if chars[i] != chars[-(i+1)]:
13+
return False
14+
else:
15+
if chars[i] != chars[-(i+1)]:
16+
return False
17+
18+
return True

0 commit comments

Comments
 (0)