1721. Swapping Nodes in a Linked List
https://leetcode.com/problems/swapping-nodes-in-a-linked-list
Description
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:
Example 3:
Example 4:
Example 5:
Constraints:
The number of nodes in the list is
n
.1 <= k <= n <= 105
0 <= Node.val <= 100
ac
Last updated