nference processing pipelines may represent records as singly linked lists while preserving object identity for downstream consumers. Given the head of a singly linked list, swap the first and second nodes by changing pointers, then return the new head.
Do not swap only the values stored in the nodes. Preserve every node object and the relative order of all nodes after the first two.
The input is either None or a reference to a ListNode object with fields val and next. The output is the head reference of the same list after the first two nodes are exchanged. The evaluator serializes the resulting list as an array of values. Test case inputs use arrays as a concise serialization of linked lists, where [] represents None.
def swap_first_two(head):