Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def isPalindrome(self, s: str) -> bool:
- """ Have two pointers step inwards, comparing the character at each index.
- """
- l = -1
- r = len(s)
- while l < r:
- l += 1
- while l < len(s) and not s[l].lower().isalnum():
- l += 1
- r -= 1
- while r >= 0 and not s[r].lower().isalnum():
- r -= 1
- if l >= len(s) and r >= 0:
- return False
- if r < 0 and l < len(s):
- return False
- if l >= len(s) and r < 0:
- return True
- if s[l].lower() != s[r].lower():
- return False
- return True
Advertisement
Add Comment
Please, Sign In to add comment