104. Maximum Depth of Binary Tree.go

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 Tree.go)