반응형
leetcode.com/problems/palindrome-linked-list/
# 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: ListNode) -> bool:
lst = []
while head:
lst.append(head.val)
head = head.next
return lst==lst[::-1]
댓글