Split the singly linked list into exactly k consecutive parts, preserving node order. Make their lengths differ by at most 1, with longer parts before shorter parts. Return an array containing the head of each part. Some parts can be empty. In examples and test inputs, arrays show list values from head to tail; each [] in the output represents an empty part.
Example 1:
Input: head = [1,2,3,4,5,6,7]
k = 3
Output: [[1,2,3],[4,5],[6,7]]Explanation: Seven nodes split into three parts have lengths 3, 2, and 2. The extra node goes in the first part, and all nodes stay in their original order.
Example 2:
Input: head = [8,9]
k = 4
Output: [[8],[9],[],[]]Explanation: There are more parts than nodes. Put one node in each of the first two parts and leave the final two parts empty.
Example 3:
Input: head = []
k = 2
Output: [[],[]]Explanation: The input list is empty, but the result must still contain exactly two parts. Both parts are empty.
Constraints:
- The list contains between
0and1000nodes. 0 <= Node.val <= 10001 <= k <= 50