class Solution {
public:
int reverse(int x) {
long long ans1=2147483647;
long long ans2=-2147483648;
int fg=0;
long long x1=(long long)x;
if(x1<0) fg=1,x1=-x1;
long long t=0;
while(x1!=0)
{
int cont=x1%10;
t=t*10+cont;
x1/=10;
}
if(fg) t=-t;
if(fg)
{
if(t<ans2) return 0;
else return t;
}
else{
if(t>ans1) return 0;
else return t;
}
}
};
421

被折叠的 条评论
为什么被折叠?



