[Python] 3 approaches - Clean & Concise
\u2714\uFE0F Solution 1: BFS\npython\nclass Solution:\n    def connect(self, root: \'Node\') -> \'Node\':\n        if root == None: return None\n\n        q = d
**\u2714\uFE0F Solution 1: BFS**\n```python\nclass Solution:\n    def connect(self, root: \'Node\') -> \'Node\':\n        if root == None: return None\n\n        q = deque([root])\n        while q:\n            prev = None\n            for _ in range(len(q)):\n                curr = q.popleft()\n                if prev != None:\n                    prev.next = curr\n                prev = curr\n\n                if curr.left != None:\n                    q.append(curr.left)\n                if curr.right != None:\n                    q.append(curr.right)\n        return root\n```\n**Complexity**\n- Time: `O(N)`, where `N` is number of nodes in the Perfect Binary Tree.\n- Space: `O(N/2)`\n\n---\n\n**\u2714\uFE0F Solution 2: DFS**\n```python\nclass Solution:\n    def connect(self, root: \'Node\') -> \'Node\':\n        if root == None: return None\n        self.connect2Nodes(root.left, root.right)\n        self.connect(root.left)\n        self.connect(root.right)\n        return root\n        \n    def connect2Nodes(self, root1, root2):\n        if root1 == None or root2 == None: return\n        root1.next = root2\n        self.connect2Nodes(root1.right, root2.left)\n```\n**Complexity**\n- Time: `O(N)`, where `N` is number of nodes in the Perfect Binary Tree.\n- Space: `O(logN)`\n\n---\n\n**\u2714\uFE0F Solution 3: Using previously established next pointers**\n```python\nclass Solution:\n    def connect(self, root: \'Node\') -> \'Node\':\n        if root == None: return None\n        \n        leftMost = root\n        while leftMost.left:\n            head = leftMost\n            leftMost = head.left\n            while head:\n                head.left.next = head.right\n                if head.next != None:\n                    head.right.next = head.next.left\n                head = head.next\n        return root\n```\n**Complexity**\n- Time: `O(N)`, where `N` is number of nodes in the Perfect Binary Tree.\n- Space: `O(1)`
[]