Given a linked list A, swap every two adjacent nodes and return its head.
NOTE: Your algorithm should use only constant space. You may not modify the values in the list; only nodes themselves can be changed.
1 <= |A| <= 106
The first and the only argument of input contains a pointer to the head of the given linked list.
Return a pointer to the head of the modified linked list.
A = 1 -> 2 -> 3 -> 4
A = 7 -> 2 -> 1
2 -> 1 -> 4 -> 3
2 -> 7 -> 1
In the first example (1, 2) and (3, 4) are the adjacent nodes. Swapping them will result in 2 -> 1 -> 4 -> 3
In the second example, 3rd element i.e. 1 does not have an adjacent node, so it won't be swapped.
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a question? Checkout Sample Codes for more details.