Java o(n) recursive solution


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