Simple Java Solution
with global variable\n\nclass Solution {\n    Node prev;\n    public Node flatten(Node head) {\n        Node cur = head;\n        while (cur != null) {\n       
with global variable\n```\nclass Solution {\n    Node prev;\n    public Node flatten(Node head) {\n        Node cur = head;\n        while (cur != null) {\n          if (cur.child != null) {\n            Node next = cur.next;\n            cur.child.prev = cur;\n            cur.next = flatten(cur.child);\n            cur.child = null;\n\t\t\t\t\t\t\n            if (next != null) {\n              prev.next = next;\n              next.prev = prev;\n            }\n          }\n\n          prev = cur;\n          cur = cur.next;\n        }\n\n        return head;\n    }    \n}\n    \n```\n\n\n<br><br>\n\nwithout using global variable\n```\n    public Node flatten(Node head) {\n        return helper(head, new Node());\n    }\n    \n    public Node helper(Node head, Node prevDummy) {\n        Node cur = head;\n        while (cur != null) {\n          if (cur.child != null) {\n            Node next = cur.next;\n            cur.child.prev = cur;\n            cur.next = helper(cur.child, prevDummy);\n            cur.child = null;\n            if (next != null) {\n              Node prev = prevDummy.next;\n              prev.next = next;\n              next.prev = prev;\n            }\n          }\n\n          prevDummy.next = cur;\n          cur = cur.next;\n        }\n\n        return head;\n    }\n```
[]