class Solution {
private:
int indicator = 0;
public:
void check(TreeNode *root, int sum) {
if(root == NULL)
return;
if(root->left == NULL && root->right == NULL) {
if(root->val == sum)
indicator = 1;
return;
}
if(root->left == NULL) {
check(root->right, sum - root->val);
return;
}
if(root->right == NULL) {
check(root->left, sum - root->val);
return;
}
check(root->left, sum - root->val);
check(root->right, sum - root->val);
}
bool hasPathSum(TreeNode* root, int sum) {
check(root, sum);
if(indicator == 1)
return true;
else
return false;
}
};