TheAlgorithms-C/leetcode/src/112.c
2020-05-29 20:23:24 +00:00

10 lines
278 B
C

bool hasPathSum(struct TreeNode *root, int sum)
{
if (root == NULL)
return 0;
if (!root->left && !root->right && sum - root->val == 0)
return 1;
return hasPathSum(root->left, sum - root->val) ||
hasPathSum(root->right, sum - root->val);
}