Javascript proposed solution


  • 0
    D
    var reverse = function(x) {
        const MIN_INT = -Math.pow(2, 31);
        const MAX_INT = Math.pow(2, 31) - 1;
    
        const positiveNum = (x >= 0) ? x : -x;    
        const reversedStr = parseInt(positiveNum.toString().split('').reverse().join(''));
        const reversedNum = (x >= 0) ? reversedStr : -reversedStr;
        return (reversedNum >= MIN_INT && reversedNum <= MAX_INT) ? reversedNum : 0;
    };
    

Log in to reply
 

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