美文网首页Leetcodeleetcode
104. Maximum Depth of Binary Tre

104. Maximum Depth of Binary Tre

作者: AnakinSun | 来源:发表于2019-03-26 12:15 被阅读5次
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
}

相关文章

网友评论

    本文标题:104. Maximum Depth of Binary Tre

    本文链接:https://www.haomeiwen.com/subject/tblgvqtx.html