别问,问就是dfs
class Solution {
public:
int countNodes(TreeNode* root) {
if(root==NULL){
return 0;
}
int left=countNodes(root->left);
int right=countNodes(root->right);
return left+right+1;
}
};
2024-03-13 18:22:33
别问,问就是dfs
class Solution {
public:
int countNodes(TreeNode* root) {
if(root==NULL){
return 0;
}
int left=countNodes(root->left);
int right=countNodes(root->right);
return left+right+1;
}
};