Solution in JavaScript


  • 0
    R

    var reverse = function(x) {
    var string = x.toString();
    var length = string.length;
    var str = "";
    if(string.indexOf("-") == 0) {
    str = "-";
    }
    for(var i=length; i > 0; i--) {
    str = str + string[i-1];
    }
    str = parseInt(str);
    if(str > 2147483647 || str < -2147483648) {
    str = 0;
    }
    return str;
    };


Log in to reply
 

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