Skip to content

Latest commit

 

History

History

125-ValidPalindrome

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Valid Palindrome

Problem can be found in here!

Solution: Two Pointers

def isPalindrome(s: str) -> bool:
    left, right = 0, len(s)-1
    while left < right:
        while left < right and not s[left].isalnum():
            left += 1
        while left < right and not s[right].isalnum():
            right -= 1

        if s[left].lower() != s[right].lower():
            return False

        left += 1
        right -= 1

    return True

Explanation: Please refer to link for explanation.

Time Complexity: O(n), Space Complexity: O(1)