DEV Community

Effy L.H.
Effy L.H.

Posted on

LeetCode:125. Valid Palindrome

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

Solutions

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

Submissions

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

Top comments (0)