Python with simple recursion + explanation with drawing
I divide the code into four part, check out the hashtag. \n#part1: if root is None, we want to just return None.\n#part2: : if cur.left is not None, we want to 
I divide the code into four part, check out the hashtag. \n`#part1`: if root is None, we want to just return None.\n`#part2:` : if cur.left is not None, we want to build a connection between cur.left and cur.right. See pic:\n![image](https://assets.leetcode.com/users/images/cfeb76d0-09c7-4598-bc2f-2b366fe46eca_1662378412.3597903.png)\n`#part3`:we want to build connection between node 5 and 6(see pic), if cur.next and cur.left not None.\n![image](https://assets.leetcode.com/users/images/a315abd7-21a7-43cf-ad9b-31ab3af73219_1662378740.7180765.png)\n`#part4` call left node and right node do the same thing\n\nIf this is helpful, don\'t forget give me a star and vote\n\n\n```\nclass Solution:\n    def connect(self, root: \'Optional[Node]\') -> \'Optional[Node]\':\n        if not root : return None      #part1\n        def recursion(cur):\n            if cur.left:                   #part2\n                cur.left.next = cur.right\n\n            if cur.next and cur.left:     #part3\n                cur.right.next = cur.next.left\n\n            recursion(cur.left) if cur.left else None        #part4\n            recursion(cur.right) if cur.right else None\n        \n        recursion(root)\n        return root\n```
['Recursion', 'Python']