【leetcode】二叉树的深度

 

int maxDepth(struct TreeNode* root){
    if (root == NULL) {
        return 0;
    }

    int lenLeft = maxDepth(root->left) + 1;
    int lenRight = maxDepth(root->right) + 1;

    return lenLeft > lenRight ? lenLeft : lenRight;
}

 

posted @ 2020-08-24 09:29  温暖了寂寞  阅读(109)  评论(0编辑  收藏  举报