###### tags: `leetcode` `python3` cited by = https://hackmd.io/2KBqq0S0TqKvtqUHUhyyTg?edit # Verifying the answer from tonylee0123 for Leetcode #7 ref = https://leetcode.com/problems/reverse-integer/discuss/4055/Golfing-in-Python ```python= class Solution(object): def reverse(self, x): s = (x > 0) - (x < 0) # +1, -1, 0 r = int(str(x*s)[::-1]) # x*s = abs(x) # abs() is built-in return s*r * (r < 2**31) ``` ## It doesn't check overflow of inputs ```typescript= Input is -2147483650 Input < min, should return 0 Output is -563847412 Output is fine return -563847412 ``` ## Its check for overflow of outputs are not exactly correct ```typescript= input=-8463847412, its rev is -2**31=-2147483648 Input is -8463847412 Input < min, should return 0 output is fine return 0 ```