LeetCode222. 完全二叉树的节点个数

题目

代码

 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 };

 

posted @ 2021-03-09 18:16  Uitachi  阅读(38)  评论(0)    收藏  举报