
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

def isPalindrome(head: ListNode) -> bool:
    vals = []
    current = head
    while current:
        vals.append(current.val)
        current = current.next
    return vals == vals[::-1]

# Example usage:
# Example 1: head = [1,2,2,1]
head1 = ListNode(1, ListNode(2, ListNode(2, ListNode(1))))
print(isPalindrome(head1))  # Output: True

# Example 2: head = [1,2]
head2 = ListNode(1, ListNode(2))
print(isPalindrome(head2))  # Output: False
