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

[pull] master from youngyangyang04:master #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 11 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
Sep 30, 2022
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit Hold shift + click to select a range
8309641
add 0055 go tanxin
Galaxies2580 Sep 26, 2022
37d518f
添加0222.完全二叉树的节点个数Go版本.md
Galaxies2580 Sep 26, 2022
f109f92
添加559.n叉树的最大深度Go版本
Galaxies2580 Sep 26, 2022
626f985
Update 链表理论基础 about rust
fwqaaq Sep 26, 2022
9b7cf50
增加0045跳跃游戏的go贪心版本和python贪心版本二
Galaxies2580 Sep 27, 2022
2846071
Update 0019.删除链表的倒数第N个节点.md
Flow-sandyu Sep 27, 2022
87c5053
Update 0019.删除链表的倒数第N个节点.md
Flow-sandyu Sep 27, 2022
5252cfc
Update 链表理论基础.md
fwqaaq Sep 28, 2022
f6cfaf1
Merge pull request #1662 from Galaxies2580/master
youngyangyang04 Sep 30, 2022
a8d946c
Merge pull request #1664 from Jack-Zhang-1314/patch-3
youngyangyang04 Sep 30, 2022
180c08f
Merge pull request #1665 from Flow-sandyu/master
youngyangyang04 Sep 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
添加0222.完全二叉树的节点个数Go版本.md
  • Loading branch information
Galaxies2580 committed Sep 26, 2022
commit 37d518f77632a920bb1dbf84a9ab34472437c431
27 changes: 27 additions & 0 deletions problems/0222.完全二叉树的节点个数.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,33 @@ func countNodes(root *TreeNode) int {
}
```

迭代法

```go
func countNodes(root *TreeNode) int {
if root == nil {
return 0
}
q := list.New()
q.PushBack(root)
res := 0
for q.Len() > 0 {
n := q.Len()
for i := 0; i < n; i++ {
node := q.Remove(q.Front()).(*TreeNode)
if node.Left != nil {
q.PushBack(node.Left)
}
if node.Right != nil {
q.PushBack(node.Right)
}
res++
}
}
return res
}
```



## JavaScript:
Expand Down

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