Skip to content

Commit 9b2784c

Browse files
pmjuupmjuu
pmjuu
authored and
pmjuu
committed
feat: solve valid palindrome
1 parent 270473d commit 9b2784c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

valid-palindrome/pmjuu.py

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

0 commit comments

Comments
 (0)