Why is my javascript solution failing?


  • 0
    N

    The following code is failing for -2147447412

    /**
     * @param {number} x
     * @return {boolean}
     */
    var isPalindrome = function(x) {
        var old = x;
        var mirror = 0;
        
        while(x) {
            mirror = mirror*10 + x%10;
            x = parseInt(x / 10);
        }
        return mirror === old;
    };
    

  • 0
    W

    You ignore negative number

    test for -2147447412, right is false, you return true


Log in to reply
 

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