TheAlgorithms-C/leetcode/src/112.c

10 lines
278 B
C
Raw Normal View History

bool hasPathSum(struct TreeNode *root, int sum)
{
2019-09-26 23:29:31 +08:00
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);
2019-09-26 23:29:31 +08:00
}