Размер видео: 1280 X 720853 X 480640 X 360
Показать панель управления
Автовоспроизведение
Автоповтор
❤❤
Glad you like it
class Solution { public: void insertAtTail(Node*&head , Node*&tail,Node* node){ if(!head){ head = node; tail = node; return ; } tail->next = node; tail = node; } // Function to split a linked list into two lists alternately vector alternatingSplitList(struct Node* head) { // Your code here if(!head || !head->next) return {head,nullptr}; Node* node1 = nullptr , *node2 = nullptr ; Node* node1Tail = node1 , * node2Tail = node2; int i = 0; while(head){ if(i&1) insertAtTail(node2,node2Tail,head); else insertAtTail(node1,node1Tail,head); head = head->next; i++; } node1Tail->next = nullptr ; node2Tail ->next = nullptr; return {node1 , node2}; }};
❤❤
Glad you like it
class Solution {
public:
void insertAtTail(Node*&head , Node*&tail,Node* node){
if(!head){
head = node;
tail = node;
return ;
}
tail->next = node;
tail = node;
}
// Function to split a linked list into two lists alternately
vector alternatingSplitList(struct Node* head) {
// Your code here
if(!head || !head->next) return {head,nullptr};
Node* node1 = nullptr , *node2 = nullptr ;
Node* node1Tail = node1 , * node2Tail = node2;
int i = 0;
while(head){
if(i&1) insertAtTail(node2,node2Tail,head);
else insertAtTail(node1,node1Tail,head);
head = head->next;
i++;
}
node1Tail->next = nullptr ; node2Tail ->next = nullptr;
return {node1 , node2};
}
};