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 b1d56c8

Browse files
committed
Update 0513.找树左下方的值,添加C#递归版
1 parent 34de1fd commit b1d56c8

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,38 @@ impl Solution {
684684
}
685685
}
686686
```
687+
### C#
688+
```C#
689+
//递归
690+
int maxDepth = -1;
691+
int res = 0;
692+
public int FindBottomLeftValue(TreeNode root)
693+
{
694+
Traversal(root, 0);
695+
return res;
696+
}
697+
public void Traversal(TreeNode root, int depth)
698+
{
699+
if (root.left == null && root.right == null)
700+
{
701+
if (depth > maxDepth)
702+
{
703+
maxDepth = depth;
704+
res = root.val;
705+
}
706+
return;
707+
}
708+
if (root.left != null)
709+
{
710+
Traversal(root.left, depth + 1);
711+
}
712+
if (root.right != null)
713+
{
714+
Traversal(root.right, depth + 1);
715+
}
716+
return;
717+
}
718+
```
687719

688720
<p align="center">
689721
<a href="https://programmercarl.com/other/kstar.html" target="_blank">

0 commit comments

Comments
(0)

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