You are given a linked list.
Your task is to swap every two adjacent nodes in the linked list and return the head of the modified list.
Note that:
value of the nodes must remain unchanged.Return the head of the modified linked list.
1 → 2 → 3 → 4 → null
2 → 1 → 4 → 3 → null
The first pair (1, 2) is swapped to (2, 1). The second pair (3, 4) is swapped to (4, 3).
None
None
An empty list remains empty.
1 → null
1 → null
A list with a single node remains unchanged.
1 → 2 → 3 → null
2 → 1 → 3 → null
The pair (1, 2) is swapped to (2, 1). The last node (3) is left as is.
1 → 2 → 3 → 4 → null
2 → 1 → 4 → 3 → null