Skip to content

Latest commit

 

History

History
29 lines (20 loc) · 420 Bytes

7.md

File metadata and controls

29 lines (20 loc) · 420 Bytes

Reverse Integer

Description

link


Solution

see Code


Code

Complexity T : O(n) M : O(n)

class Solution:
    def reverse(self, x):
        """
        :type x: int
        :rtype: int
        """
        sign = [1,-1][x < 0]
        rst = sign * int(str(abs(x))[::-1])
        return rst if -(2**31)-1 < rst < 2**31 else 0