[Python 3] Using recursion || beats 98% || 36ms 🥷🏼
\npython3 []\nclass Solution:\n    def flatten(self, head: \'Optional[Node]\') -> \'Optional[Node]\':\n        def unpack(head):\n            cur = tail = head\
\n```python3 []\nclass Solution:\n    def flatten(self, head: \'Optional[Node]\') -> \'Optional[Node]\':\n        def unpack(head):\n            cur = tail = head\n            while cur:\n                if cur.child:\n                    start, end = unpack(cur.child)\n                    if cur.next: cur.next.prev = end\n                    cur.next, start.prev, end.next, cur.child = start, cur, cur.next, None\n                    cur = end\n                tail = cur\n                cur = cur.next\n            return (head, tail)\n\n        return unpack(head)[0]\n```\n![Screenshot 2023-08-03 at 20.36.39.png](https://assets.leetcode.com/users/images/d40a8935-7022-41c1-acce-a6a8740db3b5_1691084229.4738047.png)\n
['Linked List', 'Recursion', 'Python', 'Python3']