牛客题霸 NC13 二叉树的最大深度
生活随笔
收集整理的這篇文章主要介紹了
牛客题霸 NC13 二叉树的最大深度
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
https://www.nowcoder.com/practice/8a2b2bf6c19b4f23a9bdb9b233eefa73
解決方案
Go
func maxDepth(root *TreeNode) int {// write code hereif root == nil {return 0}return max(maxDepth(root.Left), maxDepth(root.Right)) + 1 }func max(a, b int) int {if a > b {return a}return b }參考文章
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的牛客题霸 NC13 二叉树的最大深度的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 牛客题霸 NC12 重建二叉树
- 下一篇: 牛客题霸 NC14 按之字形顺序打印二叉