✅ Python - Simple - Recursion
Concept: Recursion - insert the node in the list not the val, then create a new linked list and return the head of the linked list.\n\n    def flatten(self, hea
Concept: Recursion - insert the node in the list not the val, then create a new linked list and return the head of the linked list.\n\n    def flatten(self, head: \'Optional[Node]\') -> \'Optional[Node]\':\n        \n        ans = []\n        if not head:\n            return head\n        \n        def traverse(node):\n            if not node:\n                return \n            ans.append(node)\n            if node.child:\n                traverse(node.child)\n            if node.next:\n                traverse(node.next)\n                \n        traverse(head)\n        \n        head = Node(ans[0].val)\n        curr = t = head\n        for i in range(1,len(ans)):\n            head = Node(ans[i].val)\n            curr.next = head\n            head.prev = curr\n            curr = head\n        return t\n\t\t\n**Upvote if you found it useful**\n
['Linked List', 'Recursion', 'Python']