From 0d993075669743879b59c8a549783604dbbb7b2f Mon Sep 17 00:00:00 2001 From: eeee0717 <70054568+eeee0717@users.noreply.github.com> Date: Thu, 23 Nov 2023 09:38:13 +0800 Subject: [PATCH] =?UTF-8?q?Update0112.=E8=B7=AF=E5=BE=84=E6=80=BB=E5=92=8C?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0C#=E9=80=92=E5=BD=92=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0112.路径总和.md | 11 +++++++++++ 1 file changed, 11 insertions(+) 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); +} ```