Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def check_alphabet(self, s: str):
- if ord(s) >= ord('a') and ord(s) <= ord('z'):
- return True
- if ord(s) >= ord('A') and ord(s) <= ord('Z'):
- return True
- if ord(s) >= ord('0') and ord(s) <= ord('9'):
- return True
- return False
- def isPalindrome(self, s: str) -> bool:
- # remove special characters
- left = 0
- right = len(s) - 1
- while(left < right):
- while(left < len(s) and not self.check_alphabet(s[left])):
- left += 1
- while(right >= 0 and not self.check_alphabet(s[right])):
- right -= 1
- if left > right:
- break
- if s[left].lower() != s[right].lower():
- return False
- left += 1
- right += -1
- return True
Advertisement
Add Comment
Please, Sign In to add comment