mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
Update 404.左叶子之和,添加C#递归版
This commit is contained in:
@ -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">
|
||||||
|
Reference in New Issue
Block a user