Java | Step-by-step Explanation
Please upvote if this helps! Thx :D\n\nclass Solution {\n    public Node connect(Node root) {\n        if (root == null) return null;\n        connectTwoNodes(r
## Please upvote if this helps! Thx :D\n```\nclass Solution {\n    public Node connect(Node root) {\n        if (root == null) return null;\n        connectTwoNodes(root.left, root.right);\n        return root;\n    }\n    \n    private void connectTwoNodes(Node n1, Node n2){\n        if (n1 == null || n2 == null) return;\n        n1.next = n2;\n        //Connect two child nodes from the same parent node. \n        connectTwoNodes(n1.left, n1.right);\n        connectTwoNodes(n2.left, n2.right);\n        //Connect two child nodes aside from each other but from different parent nodes . \n        connectTwoNodes(n1.right, n2.left);\n    } \n}\n```
['Breadth-First Search', 'Recursion', 'Java']