Solution in JavaScript


  • 0
    P
    var reverse = function(x) {
        let a = x.toString().split('')
        let num;
        if(a[0] == '-') {
            let c = a.shift()
            num = parseInt(c +a.reverse().join(''))
        } else {
           num = parseInt(a.reverse().join(''))
        }
        
        if(Math.abs(num) > Math.pow(2, 31)) {
            num = 0;
        }
        
        return num
    };
    

Log in to reply
 

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