💢☠💫Easiest👾Faster✅💯 Lesser🧠 🎯 C++✅Python3🐍✅Java✅C✅Python🐍✅C#✅💥🔥💫Explained☠💥🔥 Beats 100
Intuition\n\n Describe your first thoughts on how to solve this problem. \n- JavaScript Code --> https://leetcode.com/problems/split-linked-list-in-parts/submis
# Intuition\n![0ehh83fsnh811.jpg](https://assets.leetcode.com/users/images/5d74bad0-1450-4444-a1db-3734461157ae_1725785056.670094.jpeg)\n<!-- Describe your first thoughts on how to solve this problem. -->\n- ***JavaScript Code -->*** https://leetcode.com/problems/split-linked-list-in-parts/submissions/1383016714?envType=daily-question&envId=2024-09-08\n- ***C++ Code -->*** https://leetcode.com/problems/split-linked-list-in-parts/submissions/1382984070?envType=daily-question&envId=2024-09-08\n- ***Python3 Code -->*** https://leetcode.com/problems/split-linked-list-in-parts/submissions/1382997065?envType=daily-question&envId=2024-09-08\n- ***Java Code -->*** https://leetcode.com/problems/split-linked-list-in-parts/submissions/1382995251?envType=daily-question&envId=2024-09-08\n- ***C Code -->*** https://leetcode.com/problems/split-linked-list-in-parts/submissions/1383017252?envType=daily-question&envId=2024-09-08\n- ***Python Code -->*** https://leetcode.com/problems/split-linked-list-in-parts/submissions/1382996527?envType=daily-question&envId=2024-09-08\n- ***C# Code -->*** https://leetcode.com/problems/split-linked-list-in-parts/submissions/1383014535?envType=daily-question&envId=2024-09-08\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n     O(N) //for c#\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n     O(K)  //for c#\n# Code\n```c []\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     struct ListNode *next;\n * };\n */\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nstruct ListNode** splitListToParts(struct ListNode* head, int k, int* returnSize) {\n    struct ListNode** ans = (struct ListNode**)calloc(sizeof(struct ListNode*), 10001);\n    *returnSize = 0;\n    struct ListNode* temp1 = head;\n    struct ListNode* curr = head;\n    int count = 0;\n\n    while (temp1 != NULL) {\n        count++;\n        temp1 = temp1->next;\n    }\n\n    int i = count % k;\n    int j = count / k;\n\n    struct ListNode* temp = head;\n\n    if (k <= count) {\n        while (temp != NULL) {\n            ans[(*returnSize)++] = curr;\n            int l = 1;\n            while (l < j && temp != NULL) {\n                l++;\n                temp = temp->next;\n            }\n            if (i > 0) {\n                i--;\n                temp = temp->next;\n            }\n            if (temp == NULL)\n                break;\n\n            curr = temp->next;\n            temp->next = NULL;\n            temp = curr;\n        }\n\n    } else {\n        while (temp != NULL) {\n            ans[(*returnSize)++] = curr;\n            curr = temp->next;\n            temp->next = NULL;\n            temp = curr;\n            k--;\n        }\n\n        while (k--)\n            ans[(*returnSize)++] = NULL;\n    }\n\n    return ans;\n}\n```\n![th.jpeg](https://assets.leetcode.com/users/images/d85b7947-10df-4c95-b6df-c6eb8afd26a1_1725785543.048366.jpeg)\n
['Linked List', 'C', 'Python', 'C++', 'Java', 'Python3', 'JavaScript', 'C#']