C++ | 8ms | Easy to Understand
C++ | 8ms | Easy to Understand\n\nclass Solution {\npublic:\n    vector<ListNode*> splitListToParts(ListNode* root, int k) {\n        vector<ListNode*> parts(k,
# C++ | 8ms | Easy to Understand\n```\nclass Solution {\npublic:\n    vector<ListNode*> splitListToParts(ListNode* root, int k) {\n        vector<ListNode*> parts(k, nullptr);\n        int len = 0;\n        for (ListNode* node = root; node; node = node->next)\n            len++;\n        int n = len / k, r = len % k;\n        ListNode* node = root, *prev = nullptr;\n        for (int i = 0; node && i < k; i++, r--) {\n            parts[i] = node;\n            for (int j = 0; j < n + (r > 0); j++) {\n                prev = node;\n                node = node->next;\n            }\n            prev->next = nullptr;\n        }\n        return parts;\n    }\n};\n```
['C', 'C++']