mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
8 lines
267 B
C
8 lines
267 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);
|
||
|
}
|