My simple solution in Javascript


  • 7
    K
    var reverse = function(x)
     {
    var sign= (x>0)?1: -1;
    x=Math.abs(x);
    var str=x.toString().split("").reverse().join("");
    var result=sign * Number(str);
    if(result>2147483647 || result < -2147483648)return 0;
    else return result;
    };

  • 0
    T

    2147483647 won't pass. It does not make sense in JS with int32


Log in to reply
 

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