1,求叶子节点个数
int leafnum(Node* root)
{
if(root == NULL)
return 0;
if(root->left == NULL && root->right ==NULL)
return 1;
return leafnum(root->left)+leafnum(root->right);
}
2,第K层节点个数
该博客介绍了如何在二叉树中计算叶子节点的数量以及找到第K层的节点数,是每日一题的解题分享。
1,求叶子节点个数
int leafnum(Node* root)
{
if(root == NULL)
return 0;
if(root->left == NULL && root->right ==NULL)
return 1;
return leafnum(root->left)+leafnum(root->right);
}
2,第K层节点个数

被折叠的 条评论
为什么被折叠?