# 34/61 test cases passed

• Blockquote

``````34 / 61 test cases passed.
Submitted: 0 minutes ago
Input:	{2,1,3,0,7,9,1,2,#,1,0,#,#,8,8,#,#,#,#,7}
Output:	{2,#,1,3,#,0,7,9,1,#,2,1,0,#,7,#}
Expected:	{2,#,1,3,#,0,7,9,1,#,2,1,0,8,8,#,7,#}
``````

Blockquote

what is wrong in this simple code

``````if(node==NULL)
return NULL;

if(node->left==NULL && node->right==NULL)
return GetNode(node->next);

if(node->left)
return node->left;

if(node->right)
return node->right;
``````

}

``````if(root) {

if(root->left)
{
if(root->right)
root->left->next=root->right;
else
root->left->next=GetNode(root->next);
}

if(root->right)
root->right->next=GetNode(root->next);

connect(root->left);
connect(root->right);
}
``````

}

• ``````> > > Got the bug:
> >
> > first right subtree should be travese   else it might be a case when
> > right subtree next pointer is not proccesed
> >
``````

``````connect(root->left);
connect(root->right);
``````

use

``````   connect(root->right);
connect(root->left);
> >
> > Full code :
``````

``````if(node==NULL)
return NULL;

if(node->left==NULL && node->right==NULL)
return GetNode(node->next);

if(node->left)
return node->left;

if(node->right)
return node->right;
``````

}

``````if(root) {

if(root->left)
{
if(root->right)
root->left->next=root->right;
else
root->left->next=GetNode(root->next);
}

if(root->right)
root->right->next=GetNode(root->next);

connect(root->right);//first right subtree should be travese
//else it might be a case when right subtree next pointer is not proccesed
connect(root->left);

}
``````

}

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