Last active
June 5, 2021 21:10
-
-
Save mertbozkir/94e7d950de5b774c1dd4d2879b66a1f5 to your computer and use it in GitHub Desktop.
String approach to reverse integer problem
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: | |
def reverse(self, x: int) -> int: | |
ex = str(x) | |
if ex[0] == "-": | |
ex2 = ex[1:] | |
print(ex2[::-1]) | |
if not((-2)**31 < int(ex2[::-1]) < 2**31 - 1): | |
return 0 | |
return ex[0] + str(int(ex2[::-1])) | |
else: | |
if not((-2)**31 < int(ex[::-1]) < 2**31 - 1): | |
return 0 | |
return int(ex[::-1]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment