DEV Community

Cover image for LeetCode DSA Series #2: 125. Valid Palindrome
David Babalola
David Babalola

Posted on

LeetCode DSA Series #2: 125. Valid Palindrome

This is a pretty easy one, finding a valid palindrome.

Here's my solution to the problem.

class Solution:
    def isPalindrome(self, s: str) -> bool:
        s = s.lower()
        new_s = ''
        for char in s:
            if char.isalnum(): 
                new_s += char
        if new_s == new_s[::-1]:
            return True
        else:
            return False
Enter fullscreen mode Exit fullscreen mode

The time and space complexity is O(N)

Top comments (0)