描述
题解
python-1
转换为字符串是最快捷的手段
"""
4:06 PM info
解答成功:
执行耗时:52 ms,击败了87.24% 的Python3用户
内存消耗:14.9 MB,击败了72.26% 的Python3用户
"""
class Solution:
def isPalindrome(self, x: int) -> bool:
if x<0:
return False
cc = str(x)
if cc == cc[::-1]:
return True
return False
python-2
当然,还是要正规的做一下
"""然后我觉得,这就是为什么不要没事重复造轮子的理由,还不如原生的快
4:46 PM info
解答成功:
执行耗时:60 ms,击败了61.73% 的Python3用户
内存消耗:14.9 MB,击败了82.69% 的Python3用户
"""
class Solution:
def isPalindrome(self, x: int) -> bool:
if x < 0:
return False
if 0 <= x < 10:
return True
ss = x
num = 0
while x > 0:
num = num * 10 + x % 10
x //= 10
return num == ss