Reverse Integer
public class Solution {
int MAX_INT_DIV_10 = Integer.MAX_VALUE / 10;
public int reverse(int x) {
boolean isNegative = x < 0 ? true : false;
if (isNegative) x = -x;
int result = 0;
while ( x > 0) {
if (result > MAX_INT_DIV_10) return 0;
int digit = x % 10;
result = 10 * result + digit;
x = x / 10;
}
if (isNegative) {
return -result;
} else {
return result;
}
}
}