[Java] O(n) time/space recursive 0ms + explanation
The idea is simple:\n1. identify the length of each part (take into account that first n%k elements should have length n/k+1, rest of elements - n/k)\n2. make a
The idea is simple:\n1. identify the length of each part (take into account that first n%k elements should have length n/k+1, rest of elements - n/k)\n2. make a recursion method that uses array of ListNodes (initially it contains only head as 0th element), goes through the current element of this array, splits it, and puts tail to the next cell of array.\nFor example:\n![image](https://assets.leetcode.com/users/olsh/image_1579607293.png)\n\nWE HAVE 4 CELLS IN ARRAY (NEED 4 PARTS)\nSIZE OF ONE PART **7/4 = 1**\nAT THE SAME TIME WE HAVE **7%4=3** PARTS WITH SIZE 2.\nSO WE JUST GO THROUGH OUR LIST TILL COUNT 2 NODES. THEN, WE MOVE TAIL TO THE NEXT CELL IN ARRAY:\n![image](https://assets.leetcode.com/users/olsh/image_1579607651.png)\n\nAFTER SOME RECURSIVE CALLS WE HAVE COMPLETE RESULT:\n![image](https://assets.leetcode.com/users/olsh/image_1579607767.png)\n\n\nCode listing:\n\n```\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n *     int val;\n *     ListNode next;\n *     ListNode(int x) { val = x; }\n * }\n */\nclass Solution {\n    public ListNode[] splitListToParts(ListNode root, int k) {\n        ListNode[]res = new ListNode[k];\n        int size = 0;\n        ListNode node = root;\n        while (node!=null){\n            size++;\n            node = node.next;\n        }\n        int partSize = size / k;\n        int partsPlus = size % k;\n        res[0]=root;\n        split(res, partSize, 1, partsPlus, root, 0);\n        return res;\n    }\n    public void split(ListNode[] nodes, int partSize, int currentSize, int partsPlus, ListNode node, int index){\n        if (node!=null){\n        int currentPartSize = (index<partsPlus)?partSize+1:partSize;\n        if (currentSize<currentPartSize) split(nodes, partSize, currentSize+1, partsPlus, node.next, index);\n        else {\n            ListNode newNode = node.next;\n            node.next = null;\n            if (index<nodes.length-1){nodes[index+1]=newNode;\n            split(nodes, partSize, 1, partsPlus, newNode, index+1);}\n        }\n    }}\n}\n```
[]