| 1 | class Solution { |
| 2 | public: |
| 3 | int reverse(int x) { |
| 4 | int rev = 0; |
| 5 | while (x!=0) { |
| 6 | int pop = x % 10; |
| 7 | x /= 10; |
| 8 | // to check that it may not overflow integer range |
| 9 | if (rev > INT_MAX/10 || (rev == INT_MAX / 10 && pop > 7)) return 0; |
| 10 | if (rev < INT_MIN/10 || (rev == INT_MIN / 10 && pop < -8)) return 0; |
| 11 | rev = rev * 10 + pop; |
| 12 | } |
| 13 | return rev; |
| 14 | } |
| 15 | }; |
| 16 |
nothing calls this directly
no outgoing calls
no test coverage detected