Reverse Integer leetcode python

class Solution(object):
    def reverse(self,x):
        """

        :param x:int
        :return: int
        """
        max_num=2147483647
        min_num=-2147483648

        flag=0
        if x<0:
            flag=1
            x=-x

        if flag==0:
            if int(str(x)[::-1])>max_num or int(str(x)[::-1])<min_num:
                return 0
            else:
                return int(str(x)[::-1])
        else:
            if int(str(x)[::-1])>max_num or int(str(x)[::-1])<min_num:
                return 0
            else:
                return -int(str(x)[::-1])

p=Solution()
print p.reverse(1534236469)

你可能感兴趣的:(python)