222. 完全二叉树的节点个数c

/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
int countNodes(struct TreeNode* root) {
if(!root) return 0;
if(!root->left&&!root->right) return 1;
return countNodes(root->left)+countNodes(root->right)+1;
}
结果:

浙公网安备 33010602011771号