题目:Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
public class Solution {
public int reverse(int x) {
// int flag;
// if(x>=0)
// flag=1;
// else
// flag=-1;
//Stack s = new Stack();
int max=0x7fffffff;
int min=0x80000000;
long s=0,t=0;
while(x!=0)
{
t = x%10;
s = 10*s+t;
if(s>max||s<min)
{
s=s>0?max:min; //若超过最大值或者最小值,则返回0
return 0;
}
x = x/10;
}
return (int)s;
}
}