文章
99
粉丝
120
获赞
8
访问
96.9k
class Solution {
public:
bool hasPathSum(TreeNode* root, int targetSum) {
if(root == NULL)
{
return false;
}
if(root->left==NULL && root->right==NULL)
{
return targetSum == root->val;
}
return hasPathSum(root->left,targetSum-root->val)||hasPathSum(root->right,targetSum-root->val);
}
};
登录后发布评论
暂无评论,来抢沙发