100% Javascript solution


  • 0
     */
    var isPalindrome = function(x) {
        if(x < 0) return false;
        var original = x;
        var length = Math.log(x) * Math.LOG10E + 1 | 0;
        var reverse = 0;
        while (original !== 0){
            var modulus = original % 10;
            original = Math.floor(original / 10);
            reverse += modulus * Math.pow(10, length - 1);
            length--;
        }
        return (x === reverse) ? true : false ;
     
    };

Log in to reply
 

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