Leetcode-Python 整数反转

Leetcode-Python 整数反转_第1张图片

class Solution:
    def reverse(self, x: int) -> int:
        if x < -2**31 or x > 2**31-1:
            return 0
        if x >= 0:
            res = int(str(x)[::-1])
        else:
            res = -1*int(str(x)[1:][::-1])
        if res < -2**31 or res > 2**31-1:
            return 0
        return res

github项目地址:https://github.com/JockWang/LeetCode-Python

你可能感兴趣的:(Leetcode)