Javascript solution, easy with toString( )


  • 0

    Just compare the original number string with reversed number string.

    var isPalindrome = function(x) {
        if(x < 0)
            return false;
        if(x.toString().length == 1)
            return true;
        return x.toString() === x.toString().split('').reverse().join('');
    };
    

  • 0
    L

    think about x is bigger than 2^31


Log in to reply
 

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