Python solutions (Recursively, BFS+queue, DFS+stack)
def connect1(self, root):\n        if root and root.left and root.right:\n            root.left.next = root.right\n            if root.next:\n                ro
    def connect1(self, root):\n        if root and root.left and root.right:\n            root.left.next = root.right\n            if root.next:\n                root.right.next = root.next.left\n            self.connect(root.left)\n            self.connect(root.right)\n     \n    # BFS       \n    def connect2(self, root):\n        if not root:\n            return \n        queue = [root]\n        while queue:\n            curr = queue.pop(0)\n            if curr.left and curr.right:\n                curr.left.next = curr.right\n                if curr.next:\n                    curr.right.next = curr.next.left\n                queue.append(curr.left)\n                queue.append(curr.right)\n        \n    # DFS \n    def connect(self, root):\n        if not root:\n            return \n        stack = [root]\n        while stack:\n            curr = stack.pop()\n            if curr.left and curr.right:\n                curr.left.next = curr.right\n                if curr.next:\n                    curr.right.next = curr.next.left\n                stack.append(curr.right)\n                stack.append(curr.left)
['Stack', 'Depth-First Search', 'Breadth-First Search', 'Queue', 'Python']