内容简介:golang 语言 LeedCode104 二叉树的最大深度
golang 语言 LeedCode104 二叉树的最大深度
func maxDepth(root *TreeNode) int {
if root==nil {
return 0
}
if root.Left==nil && root.Right ==nil{
return 1
}
i := depth(root)
return i
}
func depth(root *TreeNode) int {
queue := list.New()
queue.PushBack(root)
var maxDeep int=0
for{
len := queue.Len()
if len== 0 {
break
}
for i:=0;i<len ;i++ {
front := queue.Front()
node := (front.Value).(*TreeNode)
queue.Remove(front)
if node.Left!=nil {
queue.PushBack(node.Left)
}
if node.Right!=nil {
queue.PushBack(node.Right)
}
}
maxDeep++
}
return maxDeep
}
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- 深度学习-自然语言模型随记
- 深度解密Go语言之map
- 饶全成:深度解密 Go 语言之反射
- 深度解密Go语言之sync.pool
- 深度解密Go语言之sync.map
- Pyro 0.3.4 发布,深度概率编程语言
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。