# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def isPalindrome(self, head: Optional[ListNode]) -> bool:
stack=[]
cur=head
while cur:
stack.append(cur)
cur=cur.next
cur=head
while stack:
p=stack.pop()
if cur.val !=p.val:
return False
cur=cur.next
return True
LEETCODE 234. 回文链表
最新推荐文章于 2024-07-31 14:30:10 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)