diff --git a/problems/0404.左叶子之和.md b/problems/0404.左叶子之和.md index c1ad602d..6dfcc886 100644 --- a/problems/0404.左叶子之和.md +++ b/problems/0404.左叶子之和.md @@ -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; + +} +```