> For the complete documentation index, see [llms.txt](https://nataliekung.gitbook.io/solutions/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nataliekung.gitbook.io/solutions/path_sum.md).

# Path Sum

bool hasPathSum(TreeNode\* root, int sum) {

if(!root) return false;

if(sum==root->val&&!root->left&&!root->right)

return true;

return (root->left&\&hasPathSum(root->left,sum-root->val)) || (root->right&\&hasPathSum(root->right,sum-root->val));

}
