Skip to main content

125. Valid Palindrome

https://leetcode.com/problems/valid-palindrome/

Python

class Solution:
def isPalindrome(self, s: str) -> bool:
letters = [char.lower() for char in s if char.isalpha() or char.isdigit()]

if len(letters) < 2:
return True

for i in range(len(letters)//2):
if letters[i] != letters[len(letters)-1-i]:
return False

return True