Update0112.路径总和,添加C#递归版
This commit is contained in:
parent
b1d56c8cff
commit
0d99307566
|
|
@ -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">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue