Skip to content

Instantly share code, notes, and snippets.

@s4553711
Created June 13, 2018 01:16
Show Gist options
  • Save s4553711/dca3f281816173181502295e8c072612 to your computer and use it in GitHub Desktop.
Save s4553711/dca3f281816173181502295e8c072612 to your computer and use it in GitHub Desktop.
class Solution {
public:
int reverse(int x) {
int rev = 0;
while (x != 0) {
int pop = x % 10;
x /= 10;
if (rev > INT_MAX/10 || rev == INT_MAX/10 && pop > 7) return 0;
if (rev < INT_MIN/10 || rev == INT_MIN/10 && pop < -8) return 0;
rev = rev * 10 + pop;
}
return rev;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment