Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This is the cheesy way i came up with.
- class Solution:
- def isPalindrome(self, s: str) -> bool:
- alphnm = ''.join(ch.lower() for ch in s if ch.isalnum())
- return alphnm == alphnm[::-1]
- #This is the two pointer solution.
- class Solution:
- def isPalindrome(self, s: str) -> bool:
- alphnm = ''.join(ch.lower() for ch in s if ch.isalnum())
- left = 0
- right = len(alphnm) - 1
- while left < right:
- if alphnm[left] != alphnm[right]:
- return False
- left += 1
- right -= 1
- return True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement