class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

def isPalindrome(head: ListNode) -> bool:
    fast = slow = head
    stack = []
    
    while fast and fast.next:
        stack.append(slow.val)
        slow = slow.next
        fast = fast.next.next
    
    if fast:
        slow = slow.next
    
    while slow:
        if stack.pop() != slow.val:
            return False
        slow = slow.next
    
    return True

def list_to_linkedlist(lst):
    if not lst:
        return None
    head = ListNode(lst[0])
    current = head
    for value in lst[1:]:
        current.next = ListNode(value)
        current = current.next
    return head

lst = [1, 2, 2, 1]
head = list_to_linkedlist(lst)
print(isPalindrome(head))  # Output: True
