Created
June 13, 2018 01:16
-
-
Save s4553711/dca3f281816173181502295e8c072612 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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