class Solution {
public:
int reverse(int x) {
if(x>2147483648-1||x<-2147483648){
return 0;
}
long int temp=10;
long int n=x;
long int sum=0;
string str=to_string(x);//
int len=str.length();
if(x<0){
len=len-1;
}
long int wei=pow(10,len-1);
for(int i=0;i<len;i++){
sum=sum+((n%temp)/(temp/10))*wei;
temp=temp*10;
wei=wei/10;
}
if(sum>2147483648-1||sum<-2147483648){
return 0;
}
return sum;
}
};
用long等于耍流氓??这个题很巧妙地用了取余运算!