Given the head of a linked list and an integer, k, return the head of the linked list after swapping the values of the kth node from the beginning and the kth node from the end of the linked list.
Note: We’ll number the nodes of the linked list starting from 1 to n.
Constraints:
n number of nodes.k ≤ n ≤500Node.value ≤5000Swapping the
The three-pass approach uses two pointers to find and swap the
Given the head of a linked list and an integer, k, return the head of the linked list after swapping the values of the kth node from the beginning and the kth node from the end of the linked list.
Note: We’ll number the nodes of the linked list starting from 1 to n.
Constraints:
n number of nodes.k ≤ n ≤500Node.value ≤5000Swapping the
The three-pass approach uses two pointers to find and swap the