Very Fast || Neat and Clean Code || Full Explained || Easy
Intuition\n Describe your first thoughts on how to solve this problem. \n- Breaking the list into parts: To properly split the list into k parts, each part shou
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- **Breaking the list into parts**: To properly split the list into k parts, each part should ideally have an equal number of nodes, but some parts might have one extra node if the list length isn\'t divisible by k.\n\n- **Breaking links:** Once you determine the number of nodes in each part, you\'ll need to break the linked list at the correct point and append each split list to ans.\n\n---\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Calculate the total length of the linked list.\n1. Determine the size of each part: \n    - The size of each part will be length // k nodes.\n    - The first rem = length % k parts will have one extra node.\n3. Split the list by iterating through it, creating the necessary splits.\n1. Return the list of parts.\n\n---\n\n\n# Complexity\n- Time complexity: $$O(N)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(N)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n---\n\n\n# Code\n```python3 []\nclass Solution:\n    def splitListToParts(self, head: Optional[ListNode], k: int) -> List[Optional[ListNode]]:\n        temp = head\n        length = 0\n        ans = []\n        while temp:\n            length += 1\n            temp = temp.next\n            \n        extra_nodes = length % k\n        part_size = length // k\n        \n        curr = head\n        for i in range(k):\n            part_head = curr\n            part_length = part_size + (1 if i < extra_nodes else 0)\n\n            for j in range(part_length-1):\n                if curr:\n                    curr = curr.next\n            \n            if curr:\n                next_part = curr.next\n                curr.next = None\n                curr = next_part\n\n            ans.append(part_head)\n\n        while len(ans)< k:\n            ans.append(None)\n        return ans\n              \n```\n---\n\n![fde74702-a4f6-4b9f-95f2-65fa9aa79c48_1716995431.3239644.png](https://assets.leetcode.com/users/images/4622a046-8a02-4f04-940e-81b44ee73fff_1725772715.769379.png)\n
['Linked List', 'Python3']