Class Solution
java.lang.Object
g1701_1800.s1721_swapping_nodes_in_a_linked_list.Solution
1721 - Swapping Nodes in a Linked List.<p>Medium</p>
<p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the</em> <code>k<sup>th</sup></code> <em>node from the beginning and the</em> <code>k<sup>th</sup></code> <em>node from the end (the list is <strong>1-indexed</strong> ).</em></p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/09/21/linked1.jpg" alt="" /></p>
<p><strong>Input:</strong> head = [1,2,3,4,5], k = 2</p>
<p><strong>Output:</strong> [1,4,3,2,5]</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> head = [7,9,6,6,7,8,3,0,9,5], k = 5</p>
<p><strong>Output:</strong> [7,9,6,6,8,7,3,0,9,5]</p>
<p><strong>Constraints:</strong></p>
<ul>
<li>The number of nodes in the list is <code>n</code>.</li>
<li><code>1 <= k <= n <= 10<sup>5</sup></code></li>
<li><code>0 <= Node.val <= 100</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
swapNodes
-