Java solution using stack. readable
\nclass Solution {\n    public Node flatten(Node head) {\n        Stack<Node> stack = new Stack<>();\n        Node travel = head;\n        while(travel != null 
```\nclass Solution {\n    public Node flatten(Node head) {\n        Stack<Node> stack = new Stack<>();\n        Node travel = head;\n        while(travel != null || !stack.isEmpty()) {\n            if(travel.child != null) {\n                if(travel.next != null) stack.push(travel.next);\n                travel.next = travel.child;\n                travel.next.prev = travel;\n                travel.child = null;\n            }else {\n                if(travel.next == null && !stack.isEmpty()) {\n                    travel.next = stack.pop();\n                    travel.next.prev = travel;\n                }\n            }\n            travel = travel.next;\n        }\n        return head;\n    }\n}\n```
[]