Skip to content

Commit

Permalink
[W4]
Browse files Browse the repository at this point in the history
valid-palindrome solution
  • Loading branch information
sun912 committed Sep 5, 2024
1 parent 6ef3bee commit 5740518
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Empty file removed two-sum/sun912.py
Empty file.
18 changes: 18 additions & 0 deletions valid-palindrome/sun912.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution:
def isPalindrome(self, s: str) -> bool:
str = list(s.lower())
chars = []
for c in str:
if (ord(c) >= ord("a") and ord(c) <= ord("z")) or (ord(c) >= ord("0") and ord(c) <= ord("9")):
chars.append(c)

for i in range(len(chars)//2):

if len(c)%2 == 0:
if chars[i] != chars[-(i+1)]:
return False
else:
if chars[i] != chars[-(i+1)]:
return False

return True

0 comments on commit 5740518

Please sign in to comment.