Solution in Javascript


  • 0
    J
    /**
     * @param {number} x
     * @return {number}
     */
    var reverse = function(x) {    
        var x = x+"";
        var rev = x.split("").reverse().join("");
        rev = parseInt(rev);
        
        if(parseInt(x)<0) {
            rev = rev * -1;
        }
        
        if(rev > 2147483647) {
            return 0;
        } else if (rev < -2147483648) {
            return 0;
        }
    
        return rev;
    };
    
    

Log in to reply
 

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