C# DFS
\npublic class Solution {\n    public Node Flatten(Node head) {\n        if (head == null) return null;\n        DFS(head);\n        return head;\n    }\n\n    
```\npublic class Solution {\n    public Node Flatten(Node head) {\n        if (head == null) return null;\n        DFS(head);\n        return head;\n    }\n\n    private Node DFS(Node head) {\n        var cur = head;\n\n        while (cur != null && cur.child == null) {\n            cur = cur.next;\n        }\n\n        if (cur != null) {\n            var next = cur.next;\n            var childHead = DFS(cur.child);\n            cur.child = null;\n            cur.next = childHead;\n            childHead.prev = cur;\n            // go down to the child end\n            var curChild = childHead;\n            while (curChild.next != null) {\n                curChild = curChild.next;\n            }\n\n            // connect with the next\n            curChild.next = next;\n            if (next != null)  next.prev = curChild;\n            DFS(next);\n        }\n\n        return head;\n    }\n}\n```
[]