Different python solutions
Solution 1: recursive solution\n\n    def flatten(self, head: \'Node\') -> \'Node\':\n        def recursive(h):\n            p_prev, p = None, h\n            wh
Solution 1: recursive solution\n```\n    def flatten(self, head: \'Node\') -> \'Node\':\n        def recursive(h):\n            p_prev, p = None, h\n            while p and not p.child:\n                p_prev, p = p, p.next\n            if not p:\n                return h, p_prev\n            else:\n                p_head, p_tail = recursive(p.child)\n                p_nxt = p.next\n                p.child = None\n                p.next = p_head\n                p_head.prev = p\n                p_tail.next = p_nxt\n                if not p_nxt:\n                    return h, p_tail\n                else:\n                    p_nxt.prev = p_tail\n                    return h, recursive(p_nxt)[1]\n        \n        if not head:\n            return head\n        else:\n            return recursive(head)[0]\n```\n\nSolution 2:\n```\n    def flatten(self, head: \'Node\') -> \'Node\':\n        if not head:\n            return None\n        p = head\n        while p:\n            if not p.child:\n                p = p.next\n            else:\n                q = p.child\n                while q.next:\n                    q = q.next\n                q.next = p.next\n                if p.next:\n                    p.next.prev = q\n                p.next = p.child\n                p.child.prev = p\n                p.child = None\n        return head\n```
[]