C++|| SLIPT LINKED LIST INTO PARTS || EASY TO UNDERSTAND || solution
Please upvote to motivate me in my quest of documenting all leetcode solutions(to help the community). HAPPY CODING:)\nAny suggestions and improvements are alwa
**Please upvote to motivate me in my quest of documenting all leetcode solutions(to help the community). HAPPY CODING:)\nAny suggestions and improvements are always welcome**\n```\nclass Solution {\npublic:\n    vector<ListNode*> splitListToParts(ListNode* head, int k) {\n        vector<ListNode*> ans;\n        ListNode* temp=head;\n        if(k==0)\n        return ans;\n        int l=0;\n        while(temp!=NULL)\n        {\n            l++;\n            temp=temp->next;\n        }\n        int len=l/k;\n        int distribute=l%k;\n        ListNode *prev=NULL,*node=head;\n        int i=0;\n        while(node!=NULL and i<k){\n            ans.push_back(node);\n            for(int j=0;j<len+(distribute>0?1:0);j++)\n            {\n                prev=node;\n                node=node->next;\n            }\n            prev->next=NULL;\n            i++;\n            distribute--;\n        }\n        while(l<k)\n        {\n            ans.push_back(NULL);\n            l++;\n        }\n        return ans;\n    }\n};\n```
['C']