美文网首页
LeetCode(2-反转整数)(Python)

LeetCode(2-反转整数)(Python)

作者: TinyShu | 来源:发表于2018-09-05 17:53 被阅读0次
image.png
解法一(36 ms 99.60%):
class Solution(object):
    def reverse(self, x):
        """
        :type x: int
        :rtype: int
        """
        if x>=0:
            temp=int(str(x)[::-1])
            if temp>2**31-1:
                return 0
            else:
                return temp
        else:
            temp=int('-'+str(-x)[::-1])
            if temp<-2**31:
                return 0
            else:
                return temp

相关文章

网友评论

      本文标题:LeetCode(2-反转整数)(Python)

      本文链接:https://www.haomeiwen.com/subject/kgtzwftx.html