diff --git a/problems/0112.路径总和.md b/problems/0112.路径总和.md index be03f719..f1ce7637 100644 --- a/problems/0112.路径总和.md +++ b/problems/0112.路径总和.md @@ -1511,6 +1511,17 @@ impl Solution { } } +``` +### C# +```C# +// 0112.路径总和 +// 递归 +public bool HasPathSum(TreeNode root, int targetSum) +{ + if (root == null) return false; + if (root.left == null && root.right == null && targetSum == root.val) return true; + return HasPathSum(root.left, targetSum - root.val) || HasPathSum(root.right, targetSum - root.val); +} ```
diff --git a/problems/0257.二叉树的所有路径.md b/problems/0257.二叉树的所有路径.md
index 44c0fd85..9ba165c7 100644
--- a/problems/0257.二叉树的所有路径.md
+++ b/problems/0257.二叉树的所有路径.md
@@ -900,6 +900,43 @@ impl Solution {
}
}
```
+### C#
+```C#
+public IList
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;
+
+}
+```