思路:将字符串考虑成双向列表
1.循环列表,并从头、尾相继抛出字符
2.循环结束,字符相符,返回值
具体代码如下:
class Solution:
def isPalindrome(self, x: int) -> bool:
lst_x=list(str(x)) #int CONVERT as String
isMatch=True
while len(lst_x)>1 and isMatch: #LOOP LIST
first=lst_x.pop()
last=lst_x.pop(0)
if not first==last:
isMatch=False
return isMatch
来源:oschina
链接:https://my.oschina.net/tedzheng/blog/3167434