mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Update0112.路径总和,添加C#递归版
This commit is contained in:
@ -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">
|
||||
|
Reference in New Issue
Block a user