Solution in Java


  • 0
    P
      ```public int reverse(int x){
            // Prevent result overflow 
            long intput = (long)x;
            long output = 0;
            while(0!=intput){
                output = output*10 + input%10;
                input/=10;
            }
            if(output<Integer.MIN_VALUE||output>Integer.MAX_VALUE){
                return 0;
            }
            return (int)output;
         }```

Log in to reply
 

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