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 19e94c7 commit 810bbf6Copy full SHA for 810bbf6
valid-palindrome/doh6077.py
@@ -0,0 +1,16 @@
1
+import re
2
+# two pointers
3
+class Solution:
4
+ def isPalindrome(self, s: str) -> bool:
5
+ # remove all alphanumeric characters and convert all uppercase letters into lowercase letters
6
+ cleaned_s = re.sub(r'[^a-zA-Z0-9]', '', s).lower()
7
+ n = len(cleaned_s)
8
+ left, right = 0, n -1
9
+ while left < right:
10
+ if cleaned_s[left] == cleaned_s[right]:
11
+ left += 1
12
+ right -= 1
13
+ else:
14
+ return False
15
+
16
+ return True
0 commit comments