首页 > 编程语言 > 详细

Leetcode 7. Reverse Integer(python)

时间:2016-04-04 17:44:15      阅读:123      评论:0      收藏:0      [点我收藏+]

该题比较简单,但是这道题有点问题。。。。

python中的整数运算没有没有限制,但是在该oj系统中要求对大数输出0(题目并没有说明,但是在test case中可以看出)

于是偷了个懒,,,

class Solution(object):
    def reverse(self, x):
        """
        :type x: int
        :rtype: int
        """
    	s=‘‘
    	if x==0: return 0
    	if x<0: s+=‘-‘
    	x=abs(x)
    	while x!=0:
    		s+=str(x%10)
    		x=x/10
    	i=int(s)	
    	if i>2147483647 or i<-2147483647:
    	    return 0
    	return i
        

  

Leetcode 7. Reverse Integer(python)

原文:http://www.cnblogs.com/colorss/p/5352275.html

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