1721. Swapping Nodes in a Linked List
Medium
1668
73
Add to List
Share
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
k
th
node from the beginning and the k
th
node from the end (the list is 1-indexed).Example 1:

Example 2:
Constraints:
- The number of nodes in the list is
n
.
1 <= k <= n <= 10
5
0 <= Node.val <= 100