内容简介: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 发布,深度概率编程语言
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Algorithms in Java, Part 5
Robert Sedgewick / Addison-Wesley Professional / 2003-7-25 / USD 54.99
Algorithms in Java, Third Edition, Part 5: Graph Algorithms is the second book in Sedgewick's thoroughly revised and rewritten series. The first book, Parts 1-4, addresses fundamental algorithms, data......一起来看看 《Algorithms in Java, Part 5》 这本书的介绍吧!