Solution in JavaScript API


  • 0
    X
    /**
     * @param {number} x
     * @return {number}
     */
    var reverse = function(x) {
        var min = (1<<31),
            max = Math.pow(2, 31),
            isXPositive = x > 0,
            xStr = Math.abs(x).toString().split(""),
            result =  parseInt(xStr.reverse().join("")) * (isXPositive ? 1 : -1);
        
        if (result > max || result < min) {
            return 0;
        } else {
            return result;
        }
    };
    

Log in to reply
 

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