Python3 || divmod  || T/S: 90% / 99%
Here\'s the plan:\n\n1. We count the total number of nodes in the linked list.\n\n1. We calculate the base size of each part d and the remainder m, which determ
Here\'s the plan:\n\n1. We count the total number of nodes in the linked list.\n\n1. We calculate the base size of each part *d* and the remainder *m*, which determines how many parts that will have one extra node.\n2. We determine the first *m* parts, which each will have *d* + 1 nodes.\n1. We determine the remaining *k* - *m* parts, which each will have *d* nodes.\n2. We move along the linked list by *d* - 1 nodes because the part will have *d* nodes in total.\n3. We update *head* to the first node of the next part, append the current part to `ans`, and repeat to the end of the linked list.\n4. We return `ans` as the solution to the problem.\n\n\n\n```python3 []\nclass Solution:\n    def splitListToParts(self, head: ListNode, k: int) -> list[ListNode]:\n\n        node_cnt, node, ans = 0, head, []\n\n        while node:                                         # <-- 1)\n            node = node.next\n            node_cnt+=1\n            \n        d, m = divmod(node_cnt,k)                           # <-- 2)\n        \n        for _ in range(m):                                  # <-- 3)\n            cur_node = prv_node = head\n\n            for _ in range(d):\n                cur_node = cur_node.next\n\n            head, cur_node.next = cur_node.next, None\n            ans.append(prv_node)\n\n        if k-node_cnt > 0:                                  # <-- 4)\n            for n in range(k-node_cnt): \n                ans.append(None)\n\n            return ans\n\n        for _ in range(k-m):                                # <-- 5)\n\n            cur_node = prv_node= head\n\n            for _ in range(d-1):\n                cur_node = cur_node.next\n                \n            head, cur_node.next = cur_node.next, None\n            ans.append(prv_node)\n\n        return ans                                          # <-- 6)\n```\n[https://leetcode.com/problems/split-linked-list-in-parts/submissions/563229573/?envType=daily-question&envId=2024-09-08](\nhttps://leetcode.com/problems/split-linked-list-in-parts/submissions/563229573/?envType=daily-question&envId=2024-09-08)\n\nI could be wrong, but I think that time complexity is *O*(*N*) and space complexity is *O*(*K*), in which *N* ~ number of nodes, and *K* ~ number of divided parts.
['Python3']