//声明
var maxDepth func(root *TreeNode) int
//定义
maxDepth = func(root *TreeNode) int {
if root!=nil{
left:=maxDepth(root.Left)
right:=maxDepth(root.Right)
return max(left,right)+1
}
return 0
}
//实现
maxDepth(root)
---------------------------
func max(x,y int)int{
if x>y {
return x
}
return y
}
Golang 内部函数的设立(以树的最大深度为例)
最新推荐文章于 2024-08-02 20:44:15 发布