Created
February 17, 2020 19:25
-
-
Save BharathKumarS/6ed39f979a2e5141f7dde874503a08da to your computer and use it in GitHub Desktop.
Reverse an integer with -2**31 through 2**31 - 1 constraint
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
#Solution works only on LeetCode | |
class Solution: | |
def reverse(self, x: int) -> int: | |
if not x < 0: | |
y = int(str(x)[::-1]) | |
else: | |
x = x * -1 | |
y = int(str(x)[::-1]) * -1 | |
if y <= -2**31 or y >= 2**31 - 1: | |
y = 0 | |
return(y) |
Author
BharathKumarS
commented
Feb 17, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment