热门

最新

红包

立Flag

投票

同城

我的

发布
weixin_48568923
想下一行代码ing
2 年前
trueweixin_48568923

leetcode 112.路径总和
bool hasPathSum(struct TreeNode* root, int targetSum) {
if(root==NULL)
{
return false;
}
if(root->left==NULL&&root->right==NULL)
{
return targetSum==root->val;
}
if(root->left)
{
if(hasPathSum(root->left, targetSum-root->val))return true;
}
if(root->right)
{
if(hasPathSum(root->right, targetSum-root->val))return true;
}
return false;
}

CSDN App 扫码分享
分享
评论
1
打赏
  • 复制链接
  • 举报
下一条:
数据-知识
立即登录