python recursive and iterative
Recursive:\n\nclass Solution:\n    def flatten(self, head: \'Node\') -> \'Node\':\n        if not head: return None\n        def travel(node):\n            whil
Recursive:\n```\nclass Solution:\n    def flatten(self, head: \'Node\') -> \'Node\':\n        if not head: return None\n        def travel(node):\n            while node:\n                q = node.next\n                if not q: tail = node\n                if node.child:\n                    node.next = node.child\n                    node.child.prev = node\n                    t = travel(node.child)\n                    if q:\n                        q.prev = t\n                    t.next= q\n                    node.child = None\n                node = node.next\n            return tail\n        travel(head)\n        return head\n```\n\nDFS with stack:\n```\nclass Solution:\n    def flatten(self, head: \'Node\') -> \'Node\':\n        if not head: return None\n        stack = [head]; p = None\n        while stack:\n            r = stack.pop()\n            if p:\n                p.next,r.prev = r,p\n            p = r\n            if r.next:\n                stack.append(r.next)\n            if r.child:\n                stack.append(r.child)\n                r.child = None\n        return head\n```
['Recursion', 'Iterator', 'Python']