[LeetCode][python3]0007. Reverse Integer

class Solution:
def reverse(self, x: int) -> int:
sign=1
if x<0:
sign=-1
x=-x
s=str(x)
s=s[::-1]
x=int(s)*sign
if x > 2147483648-1 or x<-2147483648:
return 0
return x
N2iI -2020.03.15

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store