We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 270473d commit 9b2784cCopy full SHA for 9b2784c
valid-palindrome/pmjuu.py
@@ -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
19
20
21
+ return True
22
0 commit comments