Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f109f92

Browse files
添加559.n叉树的最大深度Go版本
1 parent 37d518f commit f109f92

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎problems/0104.二叉树的最大深度.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,29 @@ func maxdepth(root *treenode) int {
552552

553553
```
554554

555+
### 559. n叉树的最大深度
556+
557+
```go
558+
func maxDepth(root *Node) int {
559+
if root == nil {
560+
return 0
561+
}
562+
q := list.New()
563+
q.PushBack(root)
564+
depth := 0
565+
for q.Len() > 0 {
566+
n := q.Len()
567+
for i := 0; i < n; i++ {
568+
node := q.Remove(q.Front()).(*Node)
569+
for j := range node.Children {
570+
q.PushBack(node.Children[j])
571+
}
572+
}
573+
depth++
574+
}
575+
return depth
576+
}
577+
```
555578

556579
## javascript
557580

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /