class Solution:
# @return an integer
def reverse(self, x):
if not x:
return x
s = str(x)
first = s[0]
result = 0
if (first.isdigit()):
sub = int(s[::-1])
if sub < 2147483648:
result = sub
else:
sub = int(s[1:][::-1])
if sub < 2147483648:
result = int(first + s[1:][::-1])
return result
No comments:
Post a Comment