您的位置:首页 > 其它

leetcode_07. 整数反转

2019-09-11 22:19 239 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/lvpeng88/article/details/100751130

leetcode_07. 整数反转

题目

leetcode题目链接

思路分析

题目要求:逆置

做到现在最简单的一题

代码展示

class Solution:
def reverse(self, x: int) -> int:
temp=0
flag=1
if x<0:
flag=0
x=-x
while x!=0:
temp*=10
temp+=x%10
x=x//10
if flag==0:
temp=-temp
if temp<=-2**31 or temp>=2**31-1:
return 0
return temp

if __name__ == "__main__":

a = Solution()
print(a.reverse(-120))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: