Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- // Definition for a Node.
- class Node {
- public:
- int val;
- Node* prev;
- Node* next;
- Node* child;
- };
- */
- class Solution {
- public:
- Node* flatten(Node* head) {
- for(Node *curr=head; curr; curr=curr->next){
- if(curr->child){
- Node *next = curr->next;
- Node *child = curr->child;
- child->prev = curr;
- curr->next = child;
- curr->child = NULL;
- while(child->next)
- child = child->next;
- child->next = next;
- if(next)
- next->prev = child;
- }
- }
- return head;
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement