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));
}
Last updated
Was this helpful?