Skip to content

Commit 47688ba

Browse files
committed
Update 0513.找树左下角的值.md -添加C#迭代法
1 parent 29eb6f6 commit 47688ba

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

problems/0513.找树左下角的值.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,9 +716,55 @@ public void Traversal(TreeNode root, int depth)
716716
return;
717717
}
718718
```
719+
```csharp
720+
/*
721+
* @lc app=leetcode id=513 lang=csharp
722+
* 迭代法
723+
* [513] Find Bottom Left Tree Value
724+
*/
725+
726+
// @lc code=start
727+
public class Solution
728+
{
729+
public int FindBottomLeftValue(TreeNode root)
730+
{
731+
Queue<TreeNode> que = new Queue<TreeNode>();
732+
733+
if (root != null)
734+
{
735+
que.Enqueue(root);
736+
}
737+
738+
int ans = 0;
739+
while (que.Count != 0)
740+
{
741+
742+
int size = que.Count;
743+
for (var i = 0; i < size; i++)
744+
{
745+
var curNode = que.Peek();
746+
que.Dequeue();
747+
if(i == 0){
748+
ans = curNode.val;
749+
}
750+
if (curNode.left != null)
751+
{
752+
que.Enqueue(curNode.left);
753+
}
754+
if (curNode.right != null)
755+
{
756+
que.Enqueue(curNode.right);
757+
}
758+
}
759+
760+
}
761+
return ans;
762+
}
763+
}
764+
// @lc code=end
765+
```
719766

720767
<p align="center">
721768
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
722769
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
723770
</a>
724-

0 commit comments

Comments
 (0)