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 #524

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 6 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
Jan 15, 2025
Merged
Changes from 1 commit
Commits
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
添加 0102.二叉树的层序遍历- 637.二叉树的层平均值 C# 版本
637.二叉树的层平均值 C# 版本
  • Loading branch information
kingemma authored Jan 14, 2025
commit 2bcd88a096d694b295a855062339579458c0769f
29 changes: 29 additions & 0 deletions problems/0102.二叉树的层序遍历.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1599,6 +1599,35 @@ impl Solution {
}
```

#### C#:

```C# 二叉树的层平均值
public class Solution {
public IList<double> AverageOfLevels(TreeNode root) {
var result= new List<double>();
Queue<TreeNode> queue = new();
if(root !=null) queue.Enqueue(root);

while (queue.Count > 0)
{
int count = queue.Count;
double value=0;
for (int i = 0; i < count; i++)
{
var curentNode=queue.Dequeue();
value += curentNode.val;
if (curentNode.left!=null) queue.Enqueue(curentNode.left);
if (curentNode.right!=null) queue.Enqueue(curentNode.right);
}
result.Add(value/count);
}

return result;
}
}

```

## 429.N叉树的层序遍历

[力扣题目链接](https://leetcode.cn/problems/n-ary-tree-level-order-traversal/)
Expand Down

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