MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / Solution

Class Solution

C++/Reverse-Integer.cpp:1–15  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Solution {
2public:
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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected