Reverse integer就是数字翻转问题
比如数字123 变成 321 -123变成-321
注意点:要控制超过Integer的最大值和最小值
代码如下
public static int test(int x){
int res = 0;
int max = Integer.MAX_VALUE;
int min = Integer.MIN_VALUE;
while (x!=0){
res *=10;
res+=x%10;
if(res>max||res<min){
return 0;
}
x/=10;
}
return res;
}