[C++] Easy & Intuitive Recursive Solution | With Whiteboard Diagrams | No extra space
Explanation:\n\n\n\n\n/*\n// Definition for a Node.\nclass Node {\npublic:\n    int val;\n    Node* prev;\n    Node* next;\n    Node* child;\n};\n*/\n\nclass So
**Explanation:**\n\n![image](https://assets.leetcode.com/users/images/87d48c27-1f22-4c62-b916-ca0f6be093b3_1597475083.660564.png)\n\n```\n/*\n// Definition for a Node.\nclass Node {\npublic:\n    int val;\n    Node* prev;\n    Node* next;\n    Node* child;\n};\n*/\n\nclass Solution {\npublic:\n    Node* flatten(Node* head) {\n        if (!head) return nullptr;\n        Node* tail = head;\n        \n        Node* next1 = flatten(head->child);\n        Node* next2 = flatten(head->next);\n\n        if (next1) {\n            tail->next = next1;\n            while (tail->next) {\n                tail->next->prev = tail;\n                tail->child = nullptr;\n                tail = tail->next;\n            }\n        }\n        \n        tail->next = next2;\n        if (next2) {\n            next2->prev = tail;\n        }\n        \n        return head;\n    }\n};\n```
['Recursion', 'C', 'C++']