bool hasPathSum(struct TreeNode* root, int targetSum){
if(root==NULL) return false;
int temp=targetSum-root->val;
if(temp==0 && root->left==NULL && root->right==NULL) return true;
return hasPathSum(root->left,temp) || hasPathSum(root->right,temp);
}
Leetcode题库 112.路径总和_1(递归 C实现)
最新推荐文章于 2024-07-14 11:23:58 发布