Skip to content

Commit 2fc3ab8

Browse files
committed
Valid Palindrome
1 parent 817b7c2 commit 2fc3ab8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

valid-palindrome/iam-edwin.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution:
2+
def isPalindrome(self, s: str) -> bool:
3+
left = 0
4+
right = len(s) - 1
5+
6+
while left < right:
7+
while left < len(s) - 1 and not s[left].isalnum():
8+
left += 1
9+
while right > 0 and not s[right].isalnum():
10+
right -= 1
11+
12+
if left >= right:
13+
return True
14+
elif s[left].lower() != s[right].lower():
15+
return False
16+
else:
17+
left += 1
18+
right -= 1
19+
20+
return True

0 commit comments

Comments
 (0)