添加559.n叉树的最大深度Go版本

This commit is contained in:
Galaxies2580
2022-09-26 09:30:14 +08:00
parent 37d518f776
commit f109f92a31

View File

@ -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