We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c6410bb commit 7b9ffdeCopy full SHA for 7b9ffde
125-Valid-Palindrome.py
@@ -0,0 +1,19 @@
1
+class Solution:
2
+ def isPalindrome(self, s: str) -> bool:
3
+ l, r = 0, len(s) - 1
4
+ while l < r:
5
+ while l < r and not self.alphanum(s[l]):
6
+ l += 1
7
+ while l < r and not self.alphanum(s[r]):
8
+ r -= 1
9
+ if s[l].lower() != s[r].lower():
10
+ return False
11
12
13
+ return True
14
+
15
+ # Could write own alpha-numeric function
16
+ def alphanum(self, c):
17
+ return (ord('A') <= ord(c) <= ord('Z') or
18
+ ord('a') <= ord(c) <= ord('z') or
19
+ ord('0') <= ord(c) <= ord('9'))
0 commit comments