leetcode/112.c
2024-09-08 14:39:20 +08:00

24 lines
470 B
C

#include "include/TreeNode.h"
#include <stdbool.h>
bool in_order(struct TreeNode *root, int target, int sum)
{
if (!root)
return false;
if (!root->left && !root->right)
return sum + root->val == target;
return in_order(root->left, target, sum + root->val) || in_order(root->right, target, sum + root->val);
}
bool hasPathSum(struct TreeNode *root, int targetSum)
{
return in_order(root, targetSum, 0);
}
int main()
{
return 0;
}