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