Python Solution


  • 0
    M
    class Solution(object):
        def reverse(self, x):
            """
            :type x: int
            :rtype: int
            """
            str_ = str(x)
            len_ = len(str_)
            
            if str_[0] == '-':      
                new_str = '-' + str_[::-1]
                new_str = new_str[:len_]
            else:
                new_str = str_[::-1]
            
            res = int(new_str)
            
            if abs(res)>0x7FFFFFFF:
                return 0
            else:
                return(res)
    

Log in to reply
 

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