To see how Javascript simplifies the work..


  • 0
    L

    var isPalindrome = function(x) {
    if (x.toString() === x.toString().split("").reverse().join("")){
    return true;
    }
    return false;
    };


  • 0
    S

    Question says do not use extra space. If you use split() and reverse() method, JS will create extra array for them. It costs O(n) space


Log in to reply
 

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