```
class Solution {
public:
bool hasPathSum(TreeNode *root, int sum) {
if(!root){return false;}
if ( (!root->left) && (!root->right) ){
if(root->val == sum){return true;}
}
else{
sum = sum - root->val;
return (hasPathSum(root->left, sum) || hasPathSum(root->right, sum) );
}
}
};
```

This gives true for the following input :

{1} 0