Soultion in Python


  • 0
    S
    class Solution():
        def reverse(self, x):
            """
            :type x: int
            :rtype: int
            """
            flag = True
            if x < 0:
                flag = False
                
            s1 = str(abs(x))
            s2 = ''
            
            for i in range(len(s1)):
                s2 = s1[::-1]
                y = int(s2)
                if y < (2 ** 32) / 2 and y > (-2 ** 32):
                    if flag:
                        return y
                    else:
                        return (y * (-1))
                else:
                    return 0

Log in to reply
 

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