present at topmost level....
two leafs may be present at same level
(take care of this condition)
use bfs
or
int lowleaf(node *root)
{
if(root==NULL) return 0;
else
return 1+min(lowleaf(root->left),lowleaf(root->right));
}
DFS the life without backtracking
int lowleaf(node *root)
{
if(root==NULL) return 0;
else
return 1+min(lowleaf(root->left),lowleaf(root->right));
}
No comments:
Post a Comment