LeetCode:007.整数反转

class Solution:
    def reverse(self, x: int) -> int:
        if x < 0:
            x = -x
            while x % 10 == 0:
                x = x / 10
            x = int(x)
            x = str(x)
            x = list(x)
            x.reverse()
            x = ''.join(x)
            x = int(x)
            x=-x
        else:
            if x != 0:
                print(x)
                while x % 10 == 0:
                    x = x / 10
                x = int(x)
                x=str(x)
                x = list(x)
                x.reverse()
                x = ''.join(x)
                x = int(x)

            else:
                x=0
        if x<(-2)**31 or x>(2)**31:
            x=0

        return x
发布了69 篇原创文章 · 获赞 33 · 访问量 1193

猜你喜欢

转载自blog.csdn.net/dosdiosas_/article/details/105681348
今日推荐