head. Group its nodes into consecutive pairs (first with second, third with fourth, and so on) and swap the two nodes in every pair. If the number of nodes is odd, the last one stays where it is.
Return the head of the resulting list.
Move the nodes themselves by rewiring the next links; do not just swap the values stored in them.head=list_node([4, 8, 15, 16, 23]) → [8, 4, 16, 15, 23]
The pairs (4, 8) and (15, 16) trade places; 23 has no partner and stays at the end.
head=list_node([0, 9]) → [9, 0]
The only pair trades places.
head=list_node([]) → None
An empty list stays empty.
Node.val ≤ 100head=list_node([4, 8, 15, 16, 23])
[8, 4, 16, 15, 23]
Run checks the first 3 tests in your browser. Submit checks all 94 tests on the server, hidden ones included.