very simple java beats 100% , beginner friendly
\npublic Node flatten(Node head) {\n        Node temp = head ;\n        Node prev = null ;\n        Node next = null ;\n        Node child = null ;\n        Sta
```\npublic Node flatten(Node head) {\n        Node temp = head ;\n        Node prev = null ;\n        Node next = null ;\n        Node child = null ;\n        Stack<Node> s = new Stack<Node>();\n        while( temp != null || !s.isEmpty()){\n            if(temp == null){\n                next = s.pop();\n                next.prev = prev ;\n                prev.next = next ;\n                temp = next ;\n                \n            }\n            if(temp.child != null){\n                child = temp.child ;\n                temp.child = null ;\n                prev = temp;\n                if(temp.next !=null){\n                    temp.next.prev = null; \n                    s.push(temp.next);\n                }\n                temp.next = child ;\n                child.prev = temp ;\n                temp = child ;\n            }\n            else if(temp.child == null){\n                prev = temp ;\n                temp = temp.next ;\n            }\n        }\n        return head ;\n    }\n```
[]