训练一下python3的语法,刷一些水题
在本题中,学习到了python3中
1.整型范围没有限制
2.字符串翻转[::-1]
3.字符串与整型互转 str() int()
class Solution:
def reverse(self, x: int) -> int:
negative = False
if x < 0:
x = -x
negative = True
strx = str(x)
strx = strx[::-1]
print(strx)
maxInt = 2147483647
result = int(strx)
if result > maxInt:
result = 0
if negative:
result = -result
return result