Python Two Pointer


  • 0
    class Solution(object):
        def isPalindrome(self, s):
            leftidx, rightidx = 0, len(s) - 1
            while leftidx < rightidx:
                while leftidx < rightidx and not s[leftidx].isalnum():
                    leftidx += 1
                while leftidx < rightidx and not s[rightidx].isalnum():
                    rightidx -= 1
                if s[leftidx].lower() != s[rightidx].lower():
                    return False
                leftidx, rightidx = leftidx + 1, rightidx - 1
            return True
    

Log in to reply
 

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