Beats 100! Diagramatic explanation with comments!
\n# Approach\nFirstly we\'ll be creating our answer vector which will store parts.\n\nNow create a temp node which will traverse through the list and find the l
\n# Approach\nFirstly we\'ll be creating our ```answer``` vector which will store parts.\n\nNow create a ```temp``` node which will traverse through the list and find the ```length``` of the list.\n\n- ```partSize``` stores the minimum number of nodes per part\n\n- ```remaining``` stores the number of extra nodes to put in first few parts\n\n- Create a new pointer ```node``` pointing to ```head``` and ```prev``` pointing to ```null```\n\n- Iterate from ```i = 0 to i < k``` ```while node exists``` and make ```answer[i] = node``` which is the starting point of our part linked list.\n- Now for ```j = 0 to j < partSize``` we make update our ```prev``` and ```node```. This way we have moved ```partSize``` nodes further.\n- But as we recall, we might have some ```remaining``` nodes too, now according to the question the difference of size between two parts should ```not be more than 1``` so we need to distribute the ```remaining``` nodes as 1 node per part.\n- Therefore ```if(remaining > 0)``` we move another node further and then point the prev to null. Along with this also make sure to decrease the ```remaining``` counter.\n\n# Refer the image below\n![image.png](https://assets.leetcode.com/users/images/7013675e-5735-489a-a59c-f0e6a8a382e3_1693977520.795543.png)\n\n\n# Code\n```\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n    vector<ListNode*> splitListToParts(ListNode* head, int k) {\n        vector<ListNode*> answer(k, nullptr);\n        int length = 0;\n\n        ListNode* temp = head;\n        while(temp){\n            length++;\n            temp = temp->next;\n        }\n\n        int partSize = length/k;// minimum number of nodes per part\n        int remaining = length%k;// extra nodes to be distributed\n\n        ListNode* node = head;\n        ListNode* prev = nullptr;\n\n        for(int i = 0; node && i < k; i++){\n            answer[i] = node;\n            for(int j = 0; j < partSize; j++){\n                prev = node;\n                node = node->next;\n            }\n            if(remaining > 0){\n                prev = node;\n                node = node->next;\n                remaining--;\n            }\n            prev->next = nullptr;\n        }\n        return answer;\n    }\n};\n```
['Python', 'C++', 'Java']