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 1426dbb commit 1dfa456Copy full SHA for 1dfa456
python/0125-valid-palindrome.py
@@ -1,21 +1,7 @@
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 (
18
- ord("A") <= ord(c) <= ord("Z")
19
- or ord("a") <= ord(c) <= ord("z")
20
- or ord("0") <= ord(c) <= ord("9")
21
- )
+ new = ''
+ for a in s:
+ if a.isalpha() or a.isdigit():
+ new += a.lower()
+ return (new == new[::-1])
0 commit comments