[Python] Get Length of Linked List then Split - Clean & Concise
Idea\n- Firstly, we need to get length of the linked list start with head node, let say listSize.\n- We need to split into k parts, where the length of each par
**Idea**\n- Firstly, we need to get length of the linked list start with `head` node, let say `listSize`.\n- We need to split into `k` parts, where **the length of each part should be as equal as possible**:\n\t- Each part have the size, `partSize = listSize / k`\n\t- When dividing into `k` parts, there may have some remain elements, `remainSize = listSize % k`. We need to prioritize filling those remaining elements into earlier parts since the problem said: **parts occurring earlier should always have a size greater than or equal to parts occurring later.**\n```python\nclass Solution:\n    def splitListToParts(self, head: Optional[ListNode], k: int) -> List[Optional[ListNode]]:\n        def getLength(head):\n            cnt = 0\n            while head != None:\n                cnt += 1\n                head = head.next\n            return cnt\n\n        listSize = getLength(head)\n        partSize, remainSize = listSize // k, listSize % k\n        ans = []\n        while head != None:\n            curPartSize = partSize\n            if remainSize > 0:\n                remainSize -= 1\n                curPartSize += 1\n\n            ans.append(head)\n            for _ in range(curPartSize - 1):  # Skip curPartSize-1 times\n                head = head.next\n\n            if head == None: break\n            head.next, head = None, head.next  # Split the current part, and go next\n\n        while len(ans) < k: ans.append(None)  # Fill to get enough k parts\n        return ans\n```\nComplexity:\n- Time: `O(N)`, where `N <= 1000` is length of linked list.\n- Space: `O(N)`
[]