⬆️🆙✅ Easy to understand & Best solution 💥👏🔥
Please upvote if my solution and efforts helped you.\n***\n\n# Code\n\nclass Solution {\n    public Node flatten(Node head) {\n        Node temp = head;\n      
# Please upvote if my solution and efforts helped you.\n***\n\n# Code\n```\nclass Solution {\n    public Node flatten(Node head) {\n        Node temp = head;\n        while(temp != null){\n            Node list1Tail = temp;\n            Node list3Head = temp.next;\n            // if the node has child node then append all its node in between\n\n            if(temp.child != null){\n                // we are assuming that recursion will give us flatten output, so we just need to adjust the pointers\n                Node list2Head = flatten(temp.child);\n                \n                // find list2 tail\n                Node list2Tail = list2Head;\n                while(list2Tail.next != null){\n                    list2Tail = list2Tail.next;\n                }\n\n                // attach the lists\n                list1Tail.next = list2Head;\n                list2Head.prev = list1Tail;\n                list2Tail.next = list3Head;\n                if(list3Head != null)\n                    list3Head.prev = list2Tail;\n                temp.child = null;\n            }\n            temp = temp.next;\n        }\n        return head;\n    }\n}\n```\n![95b59d87-f0ce-4723-8fa9-f4538bdede4c_1715820685.5989218.jpeg](https://assets.leetcode.com/users/images/5637ccdf-accf-48dc-a74e-22c927ed1cd5_1718643784.1234424.jpeg)\n
['Linked List', 'Doubly-Linked List', 'Java']