(int x)
| 1 | class Solution { |
| 2 | |
| 3 | public int reverse(int x) { |
| 4 | boolean isNegative = x < 0; |
| 5 | |
| 6 | x = Math.abs(x); |
| 7 | |
| 8 | int num = 0; |
| 9 | |
| 10 | while (x > 0) { |
| 11 | if (Integer.MAX_VALUE / 10 < num) return 0; |
| 12 | |
| 13 | num = 10 * num + x % 10; |
| 14 | x /= 10; |
| 15 | } |
| 16 | |
| 17 | return isNegative ? -num : num; |
| 18 | } |
| 19 | } |
no outgoing calls
no test coverage detected