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

二叉树的最大深度

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
}














全部评论

相关推荐

Ivew:好像没啥问题,你没签,其他人签了,人招满了不招正常做法。
点赞 评论 收藏
分享
小马云表哥:我秋招一般是说要出国留学了
点赞 评论 收藏
分享
1 1 评论
分享
牛客网
牛客企业服务