python整数反转
class Solution(object):
def reverse(self, x):
"""
:type x: int
:rtype: int
"""
strx = str(x)
if x < 0:
x = int('-' + strx[::-1])
else:
x = int(strx[::-1])
if x > pow(2,31)-1 or x < pow(-2,31):
return 0
return x
求助大佬红色部分是怎么理解 已解决 [::-1]取相反切片
>>> a =
>>> a[::-1]
>>> b = '123'
>>> b[::-1]
'321'
>>> c = (1,2,3)
>>> c[::-1]
(3, 2, 1)
页:
[1]