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 0c7b61a

Browse files
path sum sol added
1 parent a011b92 commit 0c7b61a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

‎Leetcode/path_sum.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution
2+
{
3+
public:
4+
bool hasPathSum(TreeNode *root, int targetSum)
5+
{
6+
if (!root)
7+
{
8+
return false;
9+
}
10+
else if (!root->left && !root->right)
11+
{
12+
return (root->val == targetSum);
13+
}
14+
15+
return hasPathSum(root->left, targetSum - root->val) || hasPathSum(root->right, targetSum - root->val);
16+
}
17+
};

0 commit comments

Comments
(0)

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