solution in javascript


  • 0
    H
    var reverse = function(x) {
        var symbol = '+';
        var arr = (x + '').split('');
        if(arr[0] == '-'){
            symbol = arr.shift(); 
        }
        arr = arr.reverse();
        while(arr[0] == 0){
            arr.shift();
        }
        arr.unshift(symbol);
        var y = parseInt(arr.join(''));
        return y >= -Math.pow(2,31) && y <= Math.pow(2,31) - 1 ? y : 0;
        
    };
    

Log in to reply
 

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