forked from forging2012/JavaArithmetic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetCode7.java
More file actions
15 lines (14 loc) · 439 Bytes
/
LeetCode7.java
File metadata and controls
15 lines (14 loc) · 439 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package LeetCode;
class LeetCode7 {
public int reverse(int x) {
int rev = 0;
while (x != 0) {
int pop = x % 10;
x /= 10;
if (rev > Integer.MAX_VALUE/10 || (rev == Integer.MAX_VALUE / 10 && pop > 7)) return 0;
if (rev < Integer.MIN_VALUE/10 || (rev == Integer.MIN_VALUE / 10 && pop < -8)) return 0;
rev = rev * 10 + pop;
}
return rev;
}
}