思路:通过求余数,计算反转数字;需要注意反转后溢出的问题。

public class Solution {

public int reverse (int x) {
    // write code here
    int mod = 0;
    int newValue=0;
    int res=0;
    while(x!=0){
        mod=x%10;
        newValue = res*10+mod;
        if((newValue-mod)/10!=res)return 0; //若是溢出,则(newValue-mod)/10计算结果和原有的不一致;
        res=newValue;
         x=x/10;
    }
    return res;
}

}