Java | Beats 100% | Clean code
Complexity\n- Time complexity: O(n+k)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(k)\n Add your space complexity here, e.g. O(n) \n\n# 
# Complexity\n- Time complexity: $$O(n+k)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(k)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n  public ListNode[] splitListToParts(ListNode head, int k) {\n    var ans = new ListNode[k];\n    var len = 0;\n\n    for (var p = head; p != null; p = p.next) len++;\n\n    var a = len / k;\n    var b = len % k;\n    var p = head;\n\n    for (var i=0; i<k; i++) {\n      var l = a + (b-- > 0 ? 1 : 0);\n      if (l == 0) break;\n      ans[i] = p;\n\n      for (var j=0; j < l-1; j++) p = p.next;\n      \n      var q = p.next;\n      p.next = null;\n      p = q;\n    }\n    return ans;\n  }\n}\n```\nIf you like my solution, please upvote it!
['Linked List', 'Java']