Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- class Solution:
- def reverse(self, y):
- """
- :type x: int
- :rtype: int
- """
- if y == 0: return 0
- elif y > 0: x = y
- else: x = -y
- l = [0]*10
- ans = 0
- indlist = list(range(0,10))
- for ind in indlist:
- l[ind] = x%10
- x = int(x/10)
- for ind_r in indlist[::-1]:
- if l[ind_r]!=0:
- for ind_rs in indlist[ind_r::-1]:
- ans = (ans+l[ind_rs])/10
- if ans <= 0.2147483647 or ind_r is not 9:
- if y>0:
- return round(ans*10**(ind_r+1))
- else:
- return round(-ans*10**(ind_r+1))
- break
- else:
- return 0
- break
- test = Solution()
- print(Solution.reverse(test, 123))
Add Comment
Please, Sign In to add comment