Solution by SonaBalsam


  • 0
    S
    class Solution(object):
        def reverse(self, x):
            """
            :type x: int
            :rtype: int
            """
            
            if x > 2147483647 and x < -2147483648:
                return 0
    
            else:
                x = str(x)
                y = ""
                x_len = len(x)
                print x_len
                
    
                if x[0] == "-":
                    while x_len > 1:
                        y = y+x[x_len-1]
                        x_len -= 1
                    y = "-"+y
                    x = int(y)
                    if x < -2147483648:
                        return 0
                    else:
                        return x
    
                else:
                    x = int(x[::-1])
                    if x > 2147483647:
                        return 0
                    else:
                        return x
    

Log in to reply
 

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