Easy understand to using JavaScript & Python

  • 0
    var isPalindrome = function(s) {
        if(s==="") return true;
        s = s.replace(/\W+/g,"").toLowerCase();
        var len = s.length;
          return s.slice(0,len/2)===s.slice(len/2).split("").reverse().join("");
          len = Math.floor(len/2);
          return s.slice(0,len)===s.slice(len+1).split("").reverse().join("");
    import re
    class Solution(object):
        def isPalindrome(self, s):
            :type s: str
            :rtype: bool
            if s=="":return True
            s = re.sub(r"\W+","",s).lower()
            left = 0
            right = len(s)-1
            while left < right:
                if s[left]!=s[right]:
                    return False
                left +=1
                right -=1
            return True

Log in to reply

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