|
| 1 | +<p>Given the <code>head</code> of a singly linked list and an integer <code>k</code>, split the linked list into <code>k</code> consecutive linked list parts.</p> |
| 2 | + |
| 3 | +<p>The length of each part should be as equal as possible: no two parts should have a size differing by more than one. This may lead to some parts being null.</p> |
| 4 | + |
| 5 | +<p>The parts should be in the order of occurrence in the input list, and parts occurring earlier should always have a size greater than or equal to parts occurring later.</p> |
| 6 | + |
| 7 | +<p>Return <em>an array of the </em><code>k</code><em> parts</em>.</p> |
| 8 | + |
| 9 | +<p> </p> |
| 10 | +<p><strong class="example">Example 1:</strong></p> |
| 11 | +<img alt="" src="https://assets.leetcode.com/uploads/2021/06/13/split1-lc.jpg" style="width: 400px; height: 134px;" /> |
| 12 | +<pre> |
| 13 | +<strong>Input:</strong> head = [1,2,3], k = 5 |
| 14 | +<strong>Output:</strong> [[1],[2],[3],[],[]] |
| 15 | +<strong>Explanation:</strong> |
| 16 | +The first element output[0] has output[0].val = 1, output[0].next = null. |
| 17 | +The last element output[4] is null, but its string representation as a ListNode is []. |
| 18 | +</pre> |
| 19 | + |
| 20 | +<p><strong class="example">Example 2:</strong></p> |
| 21 | +<img alt="" src="https://assets.leetcode.com/uploads/2021/06/13/split2-lc.jpg" style="width: 600px; height: 60px;" /> |
| 22 | +<pre> |
| 23 | +<strong>Input:</strong> head = [1,2,3,4,5,6,7,8,9,10], k = 3 |
| 24 | +<strong>Output:</strong> [[1,2,3,4],[5,6,7],[8,9,10]] |
| 25 | +<strong>Explanation:</strong> |
| 26 | +The input has been split into consecutive parts with size difference at most 1, and earlier parts are a larger size than the later parts. |
| 27 | +</pre> |
| 28 | + |
| 29 | +<p> </p> |
| 30 | +<p><strong>Constraints:</strong></p> |
| 31 | + |
| 32 | +<ul> |
| 33 | + <li>The number of nodes in the list is in the range <code>[0, 1000]</code>.</li> |
| 34 | + <li><code>0 <= Node.val <= 1000</code></li> |
| 35 | + <li><code>1 <= k <= 50</code></li> |
| 36 | +</ul> |
0 commit comments