Recursive Solution with no helper method


  • 0
    9

    Recursive Solution with no helper method

    public void connect(TreeLinkNode root) {
            if(root == null) return;
            if(root.left != null){
                root.left.next = root.right;
            }
            if(root.right != null && root.next != null){
                root.right.next = root.next.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.