JAVA 1ms DFS Self Explainatory Easy
\nclass Solution {\n    public Node flatten(Node head) {\n        if(head == null) return null;\n        Node ptr = head;\n        while(ptr.next != null) ptr =
```\nclass Solution {\n    public Node flatten(Node head) {\n        if(head == null) return null;\n        Node ptr = head;\n        while(ptr.next != null) ptr = ptr.next;\n        Node p = head;\n        while(p != null){\n            if(p.child != null){\n                Node chi = p.child;\n                Node nxt = p.next;\n                p.child = null;\n                flatten(chi);\n                Node end = chi;\n                while(end.next != null) end = end.next;\n                p.next = chi;\n                chi.prev = p;\n                end.next = nxt;\n                if(nxt != null)nxt.prev = end;\n            }\n            p=p.next;\n        }\n        return head;\n    }\n}\n```
['Java']