From 34de1fd8b0fde25caef3626bf6a848f080607aed Mon Sep 17 00:00:00 2001 From: eeee0717 <70054568+eeee0717@users.noreply.github.com> Date: Tue, 21 Nov 2023 09:07:56 +0800 Subject: [PATCH] =?UTF-8?q?Update=20404.=E5=B7=A6=E5=8F=B6=E5=AD=90?= =?UTF-8?q?=E4=B9=8B=E5=92=8C=EF=BC=8C=E6=B7=BB=E5=8A=A0C#=E9=80=92?= =?UTF-8?q?=E5=BD=92=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0404.左叶子之和.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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; + +} +```