From 47688ba24829cab212fa9d3d911199cbe8afee57 Mon Sep 17 00:00:00 2001 From: Chenxue3 <71321839+Chenxue3@users.noreply.github.com> Date: Mon, 15 Jan 2024 23:10:46 +1300 Subject: [PATCH] =?UTF-8?q?Update=200513.=E6=89=BE=E6=A0=91=E5=B7=A6?= =?UTF-8?q?=E4=B8=8B=E8=A7=92=E7=9A=84=E5=80=BC.md=20-=E6=B7=BB=E5=8A=A0C#?= =?UTF-8?q?=E8=BF=AD=E4=BB=A3=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0513.找树左下角的值.md | 48 ++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/problems/0513.找树左下角的值.md b/problems/0513.找树左下角的值.md index 3cdcc801..d897bba1 100644 --- a/problems/0513.找树左下角的值.md +++ b/problems/0513.找树左下角的值.md @@ -716,9 +716,55 @@ public void Traversal(TreeNode root, int depth) return; } ``` +```csharp +/* + * @lc app=leetcode id=513 lang=csharp + * 迭代法 + * [513] Find Bottom Left Tree Value + */ + +// @lc code=start +public class Solution +{ + public int FindBottomLeftValue(TreeNode root) + { + Queue que = new Queue(); + + if (root != null) + { + que.Enqueue(root); + } + + int ans = 0; + while (que.Count != 0) + { + + int size = que.Count; + for (var i = 0; i < size; i++) + { + var curNode = que.Peek(); + que.Dequeue(); + if(i == 0){ + ans = curNode.val; + } + if (curNode.left != null) + { + que.Enqueue(curNode.left); + } + if (curNode.right != null) + { + que.Enqueue(curNode.right); + } + } + + } + return ans; + } +} +// @lc code=end +```

-