JS, 5 lines solution


  • 1

    var reverse = function (x) {
    var ans = parseInt((Math.abs(x).toString()).split("").reverse().join(""));
    ans *= x < 0 ? -1 : 1;
    return (ans > 2147483647) || (ans < -2147483648) ? 0 : ans;
    };
    beginner solution, using array.reverse() method


Log in to reply
 

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