Solution in Python for Reverse Integer


  • 0
    Y
    class Solution:
        def reverse(self, x):
            """
            :type t: int
            :rtype: int
            """
            res = 0
            y = abs(x)
            while (y != 0):
                res = 10 * res + y % 10
                y = int(y / 10)
            if res < -(2 ** 31) + 1 or res > (2 ** 31) - 1:
                return 0
            return res if x > 0 else res * (-1)

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.