题解 | #二叉树的最大深度#

二叉树的最大深度

http://www.nowcoder.com/practice/8a2b2bf6c19b4f23a9bdb9b233eefa73

/**
 * struct TreeNode {
 *	int val;
 *	struct TreeNode *left;
 *	struct TreeNode *right;
 * };
 *
 * C语言声明定义全局变量请加上static,防止重复定义
 */
/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 *
 * 
 * @param root TreeNode类 
 * @return int整型
 */;;;
int maxDepth(struct TreeNode* root ) {
    // write code here
    if(root == NULL)
        return 0;
    int DepthLeft = maxDepth(root->left)+1;
    int DepthRight = maxDepth(root->right)+1;
    
    return DepthLeft >= DepthRight ? DepthLeft : DepthRight;   
}

全部评论

相关推荐

嵌入式求职之路:可以看我经验😂,https://www.nowcoder.com/share/jump/73221730841876945
点赞 评论 收藏
分享
每晚夜里独自颤抖:1600一个月?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务