首页 > 编程语言 > 详细

leetcode Reverse Integer python

时间:2015-11-10 00:17:04      阅读:196      评论:0      收藏:0      [点我收藏+]
class Solution(object):
    def reverse(self, x):
        """
        :type x: int
        :rtype: int
        """
        answer = 0
        
        sign = 1 if x > 0 else -1
        x = abs(x)
        while x > 0:
            answer = answer * 10 + x % 10
            x/=10
        if answer > 2147483647:
            answer = 0
        return sign*answer

 

leetcode Reverse Integer python

原文:http://www.cnblogs.com/allenhaozi/p/4951600.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!