Python Solution using Two-Pointers O(N)


  • 0
    U
    class Solution(object):
        def isPalindrome(self, s):
            """
            :type s: str
            :rtype: bool
            """
            s = s.strip()
            low = 0
            high = len(s) - 1
            while low <= high:
                if not s[low].isalnum():
                    low += 1
                elif not s[high].isalnum():
                    high -= 1
                else:
                    if s[low].lower() != s[high].lower():
                        return False
                    low += 1
                    high -= 1
                
            return True
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.