叶子节点的特征:左右孩子均为NULL
代码语言:javascript复制struct node {
int val;
node *left, *right;
};
int countLeaf(node *root) {
if (!root) return 0;
else {
if (!root->left && !root->right) return 1;
return countLeaf(root->left) countLeaf(root->right);
}
}