c++, about 10 lines solution
\nNode* flatten(Node* head) {\n\tfor (Node* h = head; h; h = h->next)\n\t{\n\t\tif (h->child)\n\t\t{\n\t\t\tNode* next = h->next;\n\t\t\th->next = h->child;\n\t
```\nNode* flatten(Node* head) {\n\tfor (Node* h = head; h; h = h->next)\n\t{\n\t\tif (h->child)\n\t\t{\n\t\t\tNode* next = h->next;\n\t\t\th->next = h->child;\n\t\t\th->next->prev = h;\n\t\t\th->child = NULL;\n\t\t\tNode* p = h->next;\n\t\t\twhile (p->next) p = p->next;\n\t\t\tp->next = next;\n\t\t\tif (next) next->prev = p;\n\t\t}\n\t}\n\treturn head;\n}\n```
[]