如何统计二叉树中右 child 的个数?
这意味着我只想要标记为正确的 child 。
例。
(Left | Right)
F(Root)
G | H
T U | I J
正确的 child 是 U、H 和 J。
找到这些的算法是什么。
最佳答案
int count(Tree *r){
if(r == NULL) return 0;
int num_l=0, num_r=0;
if(r->left != NULL)
num_l = count(r->left);
if(r->right != NULL)
num_r = count(r->right)+1;
return num_l+num_r
}
关于algorithm - 如何计算二叉树中右 child 的数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2634890/