Created
September 17, 2019 23:39
-
-
Save DataSolveProblems/7fa8a6721b0e9aee664c913ce723f235 to your computer and use it in GitHub Desktop.
This file contains hidden or 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: | |
def reverse(self, x: int) -> int: | |
isNegative = x < 0 | |
x = abs(x) | |
reversed = 0 | |
while x != 0: | |
reversed = reversed * 10 + x % 10 | |
x //= 10 | |
if reversed > 2**31 - 1: | |
return 0 | |
else: | |
return reversed if not isNegative else -reversed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment