Update 404.左叶子之和,添加C#递归版
This commit is contained in:
parent
a9923f809d
commit
34de1fd8b0
|
|
@ -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">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue