Java 0ms with visual explanation
\n\n\nclass Solution {\n    public Node connect(Node root) {\n        if(root == null) return null;\n        if(root.left != null) root.left.next = root.right;\
![image](https://assets.leetcode.com/users/images/a3197575-43d6-474a-b6b7-f7005723828e_1607299930.3256361.png)\n\n```\nclass Solution {\n    public Node connect(Node root) {\n        if(root == null) return null;\n        if(root.left != null) root.left.next = root.right;\n        if(root.right != null && root.next != null) root.right.next = root.next.left;\n        connect(root.left);\n        connect(root.right);\n        return root;\n    }\n}\n```
['Java']