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

二叉树的最大深度

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

import . "nc_tools"
/*
 * type TreeNode struct {
 *   Val int
 *   Left *TreeNode
 *   Right *TreeNode
 * }
 */

/**
  * 
  * @param root TreeNode类 
  * @return int整型
*/
//递归选手请求出战
func maxDepth( root *TreeNode ) int {
    // write code here
    return maxD(root)
}

func maxD(root *TreeNode) int {
    if root == nil {
        return 0
    }
    var res int
    left := maxD(root.Left)
    right := maxD(root.Right)
    res = max(left, right) + 1
    return res
}

func max(a, b int) int {
    if a < b {
        return b
    }
    return a
}














全部评论

相关推荐

什么时候发意向:怎么连北航佬的秋招也这么难
点赞 评论 收藏
分享
09-27 00:29
东北大学 Java
伟大的麻辣烫:查看图片
阿里巴巴稳定性 74人发布 投递阿里巴巴等公司10个岗位
点赞 评论 收藏
分享
点赞 评论 收藏
分享
1 1 评论
分享
牛客网
牛客企业服务