7.反转整数

2019-04-21  本文已影响0人  王王韦王奇
class Solution:
    def reverse(self, x):
        """
        :type x: int
        :rtype: int
        """
        if x >= 0:
            s = int(str(x)[::-1])
        else:
            s = -int(str(-x)[::-1])
        if s >= -(2 ** 31) and s <= (2 ** 31) - 1:
            return s
        else:
            return 0


print(Solution.reverse(0, 123))
上一篇 下一篇

猜你喜欢

热点阅读