0 ms recursive java solution


  • 1
    S
    public void connect(TreeLinkNode root) {
            if(root == null || root.left == null) return;
            TreeLinkNode l = root.left;
            TreeLinkNode r = root.right;
            while(l != null && r != null){
                l.next = r;
                l = l.right;
                r = r.left;
            }
            connect(root.left);
            connect(root.right);
        }
    

Log in to reply
 

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