Question
The Reverse digits of an integer.
Example
Example1: x = 123, return 321
Solution
public class Solution {
public int reverse(int x) {
int temp=0;
int num=Math.abs(x);
while(num!=0){
if (temp>(Integer.MAX_VALUE-num%10)/10) //判断执行下去是否会存在越界溢出问题
return 0;
temp=temp*10+num%10;
num/=10;
}
return x>0?temp:-temp; //判断x是正数还是负数
}
}