Reverse Integer solution in Python


  • 0
    K
    class Solution(object):
        def reverse(self, x):
            """
            :type x: int
            :rtype: int
            """
            y = str(x)
            length = len(y)
            if '-' in y:
                retain = '-'
                rev = y[::-1][:-1]
                concat = retain + rev
                rtype = int(concat)
            else:
                rev = y[::-1]
                rtype = int(rev)
            if(abs(rtype) < (2**31 -1)):
                return rtype
            else:
                return 0
    
    

Log in to reply
 

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