# 回文链表

给你一个单链表的头节点 head ,请你判断该链表是否为回文链表。如果是,返回 true ;否则,返回 false

 

示例 1:

输入:head = [1,2,2,1]
输出:true

示例 2:

输入:head = [1,2]
输出:false

 

提示:

 

进阶:你能否用 O(n) 时间复杂度和 O(1) 空间复杂度解决此题?

## template ```python class ListNode: def __init__(self, x): self.val = x self.next = None class Solution: def isPalindrome(self, head: ListNode) -> bool: lst = [] node = head while node: lst.append(node.val) node = node.next start = 0 end = len(lst) - 1 while start < end: if lst[start] != lst[end]: return False start += 1 end -= 1 return True ``` ## 答案 ```python ``` ## 选项 ### A ```python ``` ### B ```python ``` ### C ```python ```