Update0112.路径总和,添加C#递归版

This commit is contained in:
eeee0717
2023-11-23 09:38:13 +08:00
parent b1d56c8cff
commit 0d99307566

View File

@ -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);
}
``` ```
<p align="center"> <p align="center">