Python DFS
DFS traverse the node and put everything into a list. The list will contain the correct order of the visited nodes.\nThen from the list rebuild a single level l
DFS traverse the node and put everything into a list. The list will contain the correct order of the visited nodes.\nThen from the list rebuild a single level linked list.\nThis algorithm has time complexity of O(n), however, the space complexity is also O(n). It is easy to understand.\n```python\nclass Solution:\n    def flatten(self, head: \'Node\') -> \'Node\':\n        if not head:return None\n        nodes = []\n        def dfs(node):\n            if node is None:return\n            nodes.append(node)\n            if node.child:dfs(node.child)\n            if node.next:dfs(node.next)\n        dfs(head)\n        head = nodes[0]\n        head.child=None\n        for i in range(1, len(nodes)):\n            node = nodes[i]\n            prev = nodes[i-1]\n            node.child=None\n            node.prev=prev\n            prev.next = node\n        return head\n```\n
[]