mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
添加559.n叉树的最大深度Go版本
This commit is contained in:
@ -552,6 +552,29 @@ func maxdepth(root *treenode) int {
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 559. n叉树的最大深度
|
||||||
|
|
||||||
|
```go
|
||||||
|
func maxDepth(root *Node) int {
|
||||||
|
if root == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
q := list.New()
|
||||||
|
q.PushBack(root)
|
||||||
|
depth := 0
|
||||||
|
for q.Len() > 0 {
|
||||||
|
n := q.Len()
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
node := q.Remove(q.Front()).(*Node)
|
||||||
|
for j := range node.Children {
|
||||||
|
q.PushBack(node.Children[j])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
depth++
|
||||||
|
}
|
||||||
|
return depth
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## javascript
|
## javascript
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user