Update 404.左叶子之和,添加C#递归版

This commit is contained in:
eeee0717
2023-11-21 09:07:56 +08:00
parent a9923f809d
commit 34de1fd8b0

View File

@ -651,6 +651,23 @@ impl Solution {
} }
} }
``` ```
### C#
```C#
// 递归
public int SumOfLeftLeaves(TreeNode root)
{
if (root == null) return 0;
int leftValue = SumOfLeftLeaves(root.left);
if (root.left != null && root.left.left == null && root.left.right == null)
{
leftValue += root.left.val;
}
int rightValue = SumOfLeftLeaves(root.right);
return leftValue + rightValue;
}
```
<p align="center"> <p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">