Runtime: 0 ms, faster than 100.00% of Java online submissions
\n\nclass Solution {\n\tpublic ListNode[] splitListToParts(ListNode head, int k) {\n\n\t\tListNode[] ans = new ListNode[k];\n\t\t\n\t\tif (k == 0 || head == nul
```\n\nclass Solution {\n\tpublic ListNode[] splitListToParts(ListNode head, int k) {\n\n\t\tListNode[] ans = new ListNode[k];\n\t\t\n\t\tif (k == 0 || head == null)\treturn ans;\n\t\t\n\t\tint size = 0;\n\n\t\tListNode temp = head;\n\n\t\twhile (temp != null) {\n\t\t\tsize++;\n\t\t\ttemp = temp.next;\n\t\t}\n\t\t\n\t\ttemp = head;\n\t\tint factor = size / k;\n\t\n\t\tint rem = size % k;\n\t\t\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\tListNode t1 = temp;\n\t\t\tint fac = factor;\n\t\t\tif (rem >= 1)\n\t\t\t\tfac += 1;\n\t\t\trem--;\n\t\t\twhile (fac != 1 && temp != null) {\n\t\t\t\ttemp = temp.next;\n\t\t\t\tfac--;\n\t\t\t}\n\t\t\tif (temp != null) {\n\t\t\t\tListNode next = temp.next;\n\t\t\t\ttemp.next = null;\n\t\t\t\ttemp = next;\n\t\t\t}\n\t\t\tans[i] = t1;\n\t\t}\n\t\treturn ans;\n\t}\n}\n```\n
[]