Most concise recursive Java solution


  • 0
    A
    public class Solution {
        public void connect(TreeLinkNode root) {
            connect(root, null);
        }
        
        private void connect(TreeLinkNode root, TreeLinkNode right) {
            if (root == null) return;
            root.next = right;
            connect(root.right, right != null? right.left : null);
            connect(root.left, root.right);
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.