1. 程式人生 > >LeetCode 反轉整數 python

LeetCode 反轉整數 python



class Solution:
    def reverse(self, x):
        """
        :type x: int
        :rtype: int
        """

        r=0
        z=abs(x)
        while(z):
            y=z%10
            z=int(z/10)
            r=int(r*10+y)
        if x<0:
            r=-r
        if(r>2147483647 or r<-2147483648):
            return 0
        else:
            return r