DEV Community

Effy L.H.
Effy L.H.

Posted on

LeetCode:125. Valid Palindrome


step1: apply .isalnum() on each character for filtering out all the alphanumeric characters in the given string .
step2: compare filtered list with the one in reversed order, if they're identical with each other, we got the string with pattern of palindrome


  • faster than 98.95%
class Solution:
    def isPalindrome(self, s: str) -> bool:
        for i in s:
            if i.isalnum():
        if result==result[::-1]:
            return True
        return False
Enter fullscreen mode Exit fullscreen mode

Top comments (0)