125. Valid Palindrome
My accepted Python solution to LeetCode problem 125, Valid Palindrome, running in 7ms.
- Difficulty: Easy
- Python
- Runtime 7ms
- Memory 22.5MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 7ms, memory 22.5MB, accepted 2025-12-23.
class Solution:
def isPalindrome(self, s: str) -> bool:
# Filter only alphanumeric characters and convert to lowercase
cleaned = ''.join(c.lower() for c in s if c.isalnum())
return cleaned == cleaned[::-1]