Swap Kth Node Values
You are given a singly linked list node
and an integer k
. Swap the value of the k
-th (0-indexed) node from the end with the k
-th node from the beginning.
Constraints
1 ≤ n ≤ 100,000
wheren
is the number of nodes innode
0 ≤ k < n
https://binarysearch.com/problems/Swap-Kth-Node-Values
Examples
Example 1
Input
- node =
- k =
1
Output
- answer =
Explanation
We swap 2
and 5
.
Example 2
Input
- node =
- k =
2
Output
- answer =
Explanation
We swap 8
with 8
.
Leave a comment