题解 | #判断一个链表是否为回文结构# 双指针求解
判断一个链表是否为回文结构
https://www.nowcoder.com/practice/3fed228444e740c8be66232ce8b87c2f
class Solution:
def isPail(self , head: ListNode) -> bool:
# write code here
lst = []
while head:
lst.append(head.val)
head = head.next
n = len(lst)
if n == 1 or n == 0:
return True
l, r = 0, n - 1
while l < r:
if lst[l] != lst[r]:
return False
l += 1
r -= 1
return True
查看30道真题和解析
