Skip to content

Commit 3fdd758

Browse files
Oct 4th : Path sum
1 parent 6af86ee commit 3fdd758

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Trees/pathSum.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ bool hasPathSum(TreeNode* root, int sum) {
99
if(!root)
1010
return 0;
1111

12-
if(!root->left && !root->right)
12+
if(!root->left && !root->right) // checks if the sum at the root is equal to target sum
1313
return sum-root->val == 0;
14-
return hasPathSum(root->left,sum-root->val) || hasPathSum(root->right,sum-root->val);
14+
return hasPathSum(root->left,sum-root->val) || hasPathSum(root->right,sum-root->val); // Traverses the tree to find the solution at one of the leaf nodes
1515
}

0 commit comments

Comments
 (0)