55.二叉树的深度

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */


int maxDepth(struct TreeNode* root){
    int left,right;
    if(root==NULL)
        return 0;
    else{
        left=left+maxDepth(root->left);
        right=right+maxDepth(root->right);
    }
    return (left>right)?left+1:right+1;
}

发布了64 篇原创文章 · 获赞 4 · 访问量 4331

猜你喜欢

转载自blog.csdn.net/yuppie__1029/article/details/105708633