Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def isPalindrome(self, s: str) -> bool:
- """ Proposed solution: convert the string to lowercase, then have two pointers
- step inwards from the outside.
- """
- s = s.lower()
- # Have them start outside of the range of the word so that I don't need to consider the
- # first iteration as a special case.
- l = -1
- r = len(s)
- while l < r:
- l += 1
- r -= 1
- # have them step inwards until they're both on a new character
- # I need to consider
- while l < r and not s[l].isalnum():
- l += 1
- while r > l and not s[r].isalnum():
- r -= 1
- # compare them
- if s[l] != s[r]:
- return False
- return True
Advertisement
Add Comment
Please, Sign In to add comment