Medium
,Linked List
,Two Pointers
1721. Swapping Nodes in a Linked List
You are 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 (the list is 1-indexed).
Example 1:
Example 2:
Constraints:
n
.k
<= n
<= 105Node.val
<= 100Yen-Chi ChenMon, May 15, 2023
Ron ChenMon, May 15, 2023
MarsgoatMon, May 15, 2023