Python Recursion: Easy-to-understand with Explanation
Intuition\n\nSince we are working with a doubly-linked list, for every node.child that we handle, we need to obtain the end node of the list at that particular 
### Intuition\n\nSince we are working with a doubly-linked list, for every `node.child` that we handle, we need to obtain the end `node` of the list at that particular level, so that we can assign its `node.next` appropriately. We can thus write a recursive function that does the following:\n\n- Loop through each `node` in the list (at that particular level).\n- Upon encountering a `node` with a `child`, call the function again starting with `node.child`.\n- Once we reach the end of the list (at that particular level), return the end `node` so we can handle it accordingly on the previous level.\n\n---\n\n### Code\n\n```python\nclass Solution:\n    def flatten(self, head: \'Node\') -> \'Node\':\n        def getTail(node):\n            prev = None\n            while node:\n                _next = node.next\n                if node.child:\n\t\t\t\t\t# ... <-> node <-> node.child <-> ...\n                    node.next = node.child\n                    node.child = None\n                    node.next.prev = node\n\t\t\t\t\t# get the end node of the node.child list\n                    prev = getTail(node.next)\n                    if _next:\n\t\t\t\t\t\t# ... <-> prev (end node) <-> _next (originally node.next) <-> ...\n                        _next.prev = prev\n                        prev.next = _next\n                else:\n                    prev = node\n                node = _next  # loop through the list of nodes\n            return prev  # return end node\n        \n        getTail(head)\n        return head\n```\n\n---\n\n### Final Result\n\n![image](https://assets.leetcode.com/users/images/a7da3193-a767-4d6d-83fc-9cc159cad0af_1635662806.4270482.png)\n\nPlease upvote if this has helped you! Appreciate any comments as well ;)
['Recursion', 'Python', 'Python3']