Reverse|Reverse Integer

/*
while循环 一直到x = 0;
拆分: temp = modint;
modint = int % 10;
int = int / 10;
【Reverse|Reverse Integer】合并modint = temp * 10 + modint;
判断Integer.MIN_VALUE < modint = temp * 10 + modint < Integer.MAX_VALUE
(modint < -8 && Integer.MIN_VALUE / 10) < temp < (Integer.MAX_VALUE / 10 && modint < 7)


*/
class Solution {
public int reverse(int x) {
int modInt = 0;
while(x != 0){
int temp = modInt;
modInt = x % 10;
x = x / 10;
if(temp < Integer.MIN_VALUE / 10 || ((temp == Integer.MIN_VALUE / 10) && (modInt < -8))) return 0;
if(temp > Integer.MAX_VALUE / 10 || ((temp == Integer.MAX_VALUE / 10) && (modInt > 7))) return 0;
modInt = temp * 10 + modInt;
}
return modInt;
}
}

    推荐阅读