Class Solution
- java.lang.Object
-
- g1701_1800.s1721_swapping_nodes_in_a_linked_list.Solution
-
public class Solution extends Object
1721 - Swapping Nodes in a Linked List.Medium
You are given the
headof a linked list, and an integerk.Return the head of the linked list after swapping the values of the
kthnode from the beginning and thekthnode from the end (the list is 1-indexed ).Example 1:

Input: head = [1,2,3,4,5], k = 2
Output: [1,4,3,2,5]
Example 2:
Input: head = [7,9,6,6,7,8,3,0,9,5], k = 5
Output: [7,9,6,6,8,7,3,0,9,5]
Constraints:
- The number of nodes in the list is
n. 1 <= k <= n <= 1050 <= Node.val <= 100
- The number of nodes in the list is
-
-
Constructor Summary
Constructors Constructor Description Solution()
-