JAVA Solution || 100% faster
\nclass Solution {\n    public Node flatten(Node head) {\n        \n        if(head == null ){\n            return head;\n        }\n        Stack<Node> stk = n
```\nclass Solution {\n    public Node flatten(Node head) {\n        \n        if(head == null ){\n            return head;\n        }\n        Stack<Node> stk = new Stack<>();\n        Node temp = head;\n        \n        while(temp.next != null || temp.child != null ){\n            \n            if(temp.child != null ){\n                if(temp.next != null)  stk.push(temp.next);\n                \n                temp.next = temp.child;\n                temp.child.prev = temp;\n                temp.child=null;\n            \n            }\n            temp = temp.next;\n        }\n        while(!stk.empty()){\n            Node x = stk.pop();\n            temp.next = x;\n            x.prev = temp;\n            while(temp.next!= null){\n                temp = temp.next;\n            }\n        }\n        \n        return head;\n        \n    }\n}\n```
['Stack', 'Java']