Easy to Understand python solution beats 93%


  • 0
    C

    class Solution(object):
    def isPalindrome(self, s):
    """
    :type s: str
    :rtype: bool
    """
    s = re.sub(r'\W+', '', s)
    s = s.lower()
    return self.isPalindromes(s,0,len(s)-1)

    def isPalindromes(self,s,start,end):
        if start<0:
            return False
        while start<end:
            if s[start]!=s[end]:
                return False
            start+=1
            end-=1
        return True

Log in to reply
 

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