题目
代码
1 class Solution { 2 public: 3 int dfs(TreeNode* root){ 4 if(root == NULL) return 0; 5 int left = dfs(root->left); //左 6 int right = dfs(root->right); //右 7 return left + right + 1; //中 8 } 9 int countNodes(TreeNode* root) { 10 return dfs(root); 11 } 12 };