[Java/C++] Clean Code
Java\n\nclass Solution {\n    public ListNode[] splitListToParts(ListNode root, int k) {\n        ListNode[] parts = new ListNode[k];\n        int len = 0;\n   
**Java**\n```\nclass Solution {\n    public ListNode[] splitListToParts(ListNode root, int k) {\n        ListNode[] parts = new ListNode[k];\n        int len = 0;\n        for (ListNode node = root; node != null; node = node.next)\n            len++;\n        int n = len / k, r = len % k; // n : minimum guaranteed part size; r : extra nodes spread to the first r parts;\n        ListNode node = root, prev = null;\n        for (int i = 0; node != null && i < k; i++, r--) {\n            parts[i] = node;\n            for (int j = 0; j < n + (r > 0 ? 1 : 0); j++) {\n                prev = node;\n                node = node.next;\n            }\n            prev.next = null;\n        }\n        return parts;        \n    }\n}\n```\n**C++**\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 : minimum guaranteed part size; r : extra nodes spread to the first r parts;\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```
[]