Leetcodeleetcode

104. Maximum Depth of Binary Tre

2019-03-26  本文已影响5人  AnakinSun
type TreeNode struct {
    Val   int
    Left  *TreeNode
    Right *TreeNode
}

func maxDepth(root *TreeNode) int {
    if root == nil {
        return 0
    }
    l := maxDepth(root.Left)
    r := maxDepth(root.Right)
    return int(math.Max(float64(l), float64(r))) + 1
}
上一篇 下一篇

猜你喜欢

热点阅读