Class Solution
java.lang.Object
g0001_0100.s0025_reverse_nodes_in_k_group.Solution
25 - Reverse Nodes in k-Group.<p>Hard</p>
<p>Given a linked list, reverse the nodes of a linked list <em>k</em> at a time and return its modified list.</p>
<p><em>k</em> is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of <em>k</em> then left-out nodes, in the end, should remain as it is.</p>
<p>You may not alter the values in the list’s nodes, only nodes themselves may be changed.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/10/03/reverse_ex1.jpg" alt="" /></p>
<p><strong>Input:</strong> head = [1,2,3,4,5], k = 2</p>
<p><strong>Output:</strong> [2,1,4,3,5]</p>
<p><strong>Example 2:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/10/03/reverse_ex2.jpg" alt="" /></p>
<p><strong>Input:</strong> head = [1,2,3,4,5], k = 3</p>
<p><strong>Output:</strong> [3,2,1,4,5]</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> head = [1,2,3,4,5], k = 1</p>
<p><strong>Output:</strong> [1,2,3,4,5]</p>
<p><strong>Example 4:</strong></p>
<p><strong>Input:</strong> head = [1], k = 1</p>
<p><strong>Output:</strong> [1]</p>
<p><strong>Constraints:</strong></p>
<ul>
<li>The number of nodes in the list is in the range <code>sz</code>.</li>
<li><code>1 <= sz <= 5000</code></li>
<li><code>0 <= Node.val <= 1000</code></li>
<li><code>1 <= k <= sz</code></li>
</ul>
<p><strong>Follow-up:</strong> Can you solve the problem in O(1) extra memory space?</p>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
reverseKGroup
-