Skip to content

Commit 34de1fd

Browse files
committed
Update 404.左叶子之和,添加C#递归版
1 parent a9923f8 commit 34de1fd

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

problems/0404.左叶子之和.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,23 @@ impl Solution {
651651
}
652652
}
653653
```
654+
### C#
655+
```C#
656+
// 递归
657+
public int SumOfLeftLeaves(TreeNode root)
658+
{
659+
if (root == null) return 0;
660+
661+
int leftValue = SumOfLeftLeaves(root.left);
662+
if (root.left != null && root.left.left == null && root.left.right == null)
663+
{
664+
leftValue += root.left.val;
665+
}
666+
int rightValue = SumOfLeftLeaves(root.right);
667+
return leftValue + rightValue;
668+
669+
}
670+
```
654671

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

0 commit comments

Comments
 (0)