Skip to content

Commit

Permalink
Revert "Update 125-Valid-Palindrome.py"
Browse files Browse the repository at this point in the history
  • Loading branch information
neetcode-gh authored Jul 15, 2022
1 parent b78ea5a commit 857360f
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions 125-Valid-Palindrome.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
class Solution:
def isPalindrome(self, s: str) -> bool:
l = 0
r = len(s)-1
while l<r:
if s[l].lower()==s[r].lower():
l+=1
r-=1
continue

elif not (65<=ord(s[l])<=90 or 97<=ord(s[l])<=122 or 48<=ord(s[l])<=57):
l+=1
elif not (65<=ord(s[r])<=90 or 97<=ord(s[r])<=122 or 48<=ord(s[r])<=57):
r-=1
else:
l, r = 0, len(s) - 1
while l < r:
while l < r and not self.alphanum(s[l]):
l += 1
while l < r and not self.alphanum(s[r]):
r -= 1
if s[l].lower() != s[r].lower():
return False
l += 1
r -= 1
return True

# Could write own alpha-numeric function
def alphanum(self, c):
return (ord('A') <= ord(c) <= ord('Z') or
ord('a') <= ord(c) <= ord('z') or
ord('0') <= ord(c) <= ord('9'))

0 comments on commit 857360f

Please sign in to comment.