Solution in javascript


  • 0
    I

    var reverse = function(x) {
    let abs = ''+Math.abs(x) ;

    let a = abs.split('');
    
    let str = '';
    a.reverse(); console.log(a);
    while(a.indexOf('0') === 0 ){
    	if(a.length===1) break;
    	a.shift();
    	 
    }  
    for(item in a){
    	str += a[item];
    }
    
    return x>=0 ? (parseInt(str) >= 2147483647 ? 0 :parseInt(str)) : (-1*parseInt(str) <= -2147483648 ? 0 :-1*parseInt(str)) ;
    

    };


Log in to reply
 

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