ขนาดวิดีโอ: 1280 X 720853 X 480640 X 360
แสดงแผงควบคุมโปรแกรมเล่น
เล่นอัตโนมัติ
เล่นใหม่
Code :-class Solution { public: vector splitListToParts(ListNode* head, int k) { vector result(k, nullptr); int listLen = 0; for (ListNode* node = head; node; node = node->next) listLen++; int baseSize = listLen / k, extraNodes = listLen % k; ListNode *node = head, *lastNode = nullptr; for (int i = 0; node && i < k; i++, extraNodes--) { result[i] = node; for (int j = 0; j < baseSize + (extraNodes > 0); j++) { lastNode = node; node = node->next; } lastNode->next = nullptr; } return result; }};
very nice
❤️❤️
Code :-
class Solution {
public:
vector splitListToParts(ListNode* head, int k) {
vector result(k, nullptr);
int listLen = 0;
for (ListNode* node = head; node; node = node->next) listLen++;
int baseSize = listLen / k, extraNodes = listLen % k;
ListNode *node = head, *lastNode = nullptr;
for (int i = 0; node && i < k; i++, extraNodes--) {
result[i] = node;
for (int j = 0; j < baseSize + (extraNodes > 0); j++) {
lastNode = node;
node = node->next;
}
lastNode->next = nullptr;
}
return result;
}
};
very nice
❤️❤️