Java Recursive Solution 6 lines 0 ms
\nclass Solution {\n    Node end = null;\n    public Node flatten(Node head) {\n        if(head == null) return end;\n\t\t// 0. head -> flatten(head.child) -> f
```\nclass Solution {\n    Node end = null;\n    public Node flatten(Node head) {\n        if(head == null) return end;\n\t\t// 0. head -> flatten(head.child) -> flatten(head.next) -> end \n\t\t// 1. flatten(head.next) -> end \n        end = flatten(head.next);\n\t\t// 2. head -> flatten(head.child) \n        head.next = flatten(head.child);\n\t\t// 3. flatten(head.child) -> flatten(head.next)\n        if(head.next != null) head.next.prev = head;\n        head.child = null;\n        return head;\n    }\n```
['Recursion', 'Java']