Solution in Javascript


  • 0
    D
    var reverse = function(x) {
        if(x<-2147483648||x>2147483647){
            return 0;
        }
        var a=x.toString();
        var b=[];
        var c=[];
        if(x<0){
            a=a.slice(1);
            b=a.split("");
            b=b.reverse();
            b=b.join("");
            b="-"+b;
            b=parseInt(b);
            if(b<-2147483648||b>2147483647){
                return 0;
            }
            return b;
        }
        else{
           c=a.split("");
           c=c.reverse();
           c=c.join(""); 
           c=parseInt(c);
            if(c<-2147483648||c>2147483647){
                return 0;
                
            }
            return c;
        }
        
        
    };

  • 0
    D
    This post is deleted!

Log in to reply
 

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