Description
Split a linked list into k consecutive linked list parts. The parts should have sizes as equal as possible. Return the result as a 2D array.
Examples
Input:
head = [1,2,3], k = 5Output:
[[1],[2],[3],[],[]]Explanation:
List has 3 nodes, k=5 parts. First 3 parts get 1 node each: [1],[2],[3]. Last 2 parts are empty: [],[].
Input:
head = [], k = 3Output:
[[],[],[]]Explanation:
When the linked list is empty, all 3 parts are empty.
Input:
head = [1,2,3,4,5], k = 2Output:
[[1,2,3],[4,5]]Explanation:
With 5 nodes and k=2, the first part gets 3 nodes and the second part gets 2 nodes.
Constraints
- •
0 ≤ list length ≤ 1000