TheAlgorithms-C/leetcode/src/112.c

8 lines
267 B
C
Raw Normal View History

2019-09-26 23:29:31 +08:00
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);
}