Skip to content

Commit 857360f

Browse files
authored
Revert "Update 125-Valid-Palindrome.py"
1 parent b78ea5a commit 857360f

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

125-Valid-Palindrome.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
class Solution:
22
def isPalindrome(self, s: str) -> bool:
3-
l = 0
4-
r = len(s)-1
5-
while l<r:
6-
if s[l].lower()==s[r].lower():
7-
l+=1
8-
r-=1
9-
continue
10-
11-
elif not (65<=ord(s[l])<=90 or 97<=ord(s[l])<=122 or 48<=ord(s[l])<=57):
12-
l+=1
13-
elif not (65<=ord(s[r])<=90 or 97<=ord(s[r])<=122 or 48<=ord(s[r])<=57):
14-
r-=1
15-
else:
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():
1610
return False
11+
l += 1
12+
r -= 1
1713
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

Comments
 (0)