其他分享
首页 > 其他分享> > 力扣 leetcode 每日一题 222. 完全二叉树的节点个数

力扣 leetcode 每日一题 222. 完全二叉树的节点个数

作者:互联网

在这里插入图片描述
别问,问就是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;
    }
};

标签:right,return,int,力扣,二叉树,countNodes,root,222,left
来源: https://blog.csdn.net/weixin_43304992/article/details/110038735