Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int reverse(int x) {
- int sign = x < 0 ? -1 : 1;
- x = Math.abs(x);
- int num = 0;
- while (x > 0) {
- int d = x%10;
- if (num > Integer.MAX_VALUE/10 || (num == Integer.MAX_VALUE/10 && d > 7)) {
- return 0;
- }
- num = num*10 + d;
- x = x/10;
- }
- return sign*num;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement