Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0d99307

Browse files
committed
Update0112.路径总和,添加C#递归版
1 parent b1d56c8 commit 0d99307

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

‎problems/0112.路径总和.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,17 @@ impl Solution {
15111511
}
15121512
}
15131513

1514+
```
1515+
### C#
1516+
```C#
1517+
// 0112.路径总和
1518+
// 递归
1519+
public bool HasPathSum(TreeNode root, int targetSum)
1520+
{
1521+
if (root == null) return false;
1522+
if (root.left == null && root.right == null && targetSum == root.val) return true;
1523+
return HasPathSum(root.left, targetSum - root.val) || HasPathSum(root.right, targetSum - root.val);
1524+
}
15141525
```
15151526

15161527
<p align="center">

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /