Leetcode 7.反转整数 By Python
2021-06-20 14:04
标签:object ret turn def class 数字 == leetcode tco 思路 python提供了方便的字符串反转方法,所以还是蛮简单的这题 注意几个坑: 代码 Leetcode 7.反转整数 By Python 标签:object ret turn def class 数字 == leetcode tco 原文地址:https://www.cnblogs.com/MartinLwx/p/9688750.html
class Solution(object):
def reverse(self, x):
"""
:type x: int
:rtype: int
"""
s = str(x)
if s[0] == '-':
num = s[1:].lstrip('0')
x = -int(num[::-1])
if x > pow(2,31)-1 or x pow(2,31)-1 or x
上一篇:Java笔试题(2)