# Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next classSolution: defisPalindrome(self, head: Optional[ListNode]) -> bool: nums = [] while head isnotNone: nums.append(head.val) head = head.next n = len(nums) if n == 1or n == 0: returnTrue i, j = 0, n-1 while i <= j: if nums[i] == nums[j]: i += 1 j -= 1 continue else: returnFalse returnTrue