/**
* 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;
}
结果:
标签:right,TreeNode,struct,222,二叉树,countNodes,return,root,节点 From: https://www.cnblogs.com/llllmz/p/18054377