Leetcode7.整数反转(中等)Python

class Solution(object):
    def reverse(self, x):
        """
        :type x: int
        :rtype: int
        """
        pos_x=abs(x)
        a=0
        while(pos_x!=0):
            b=pos_x%10
            a=b+a*10
            pos_x=pos_x//10
        if x>0 and a<=2**31-1:
            return a
        elif x<0 and a<=2**31:
            return int('-'+str(a))
        else:
            return 0

​​​​​​​ 


版权声明:本文为weixin_52313082原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。