About bst has_path_sum

Given a binary tree and a number, return true if the tree has a root-to-leaf path such that adding up all the values along the path equals the given number. Return false if no such path can be found.
#include
using namespace std;
class node
{
public:
int data;
node* left;
node* right;
node(int d)
{
data=d;
left=NULL;
right=NULL;
}
};
node* build()
{
node* root=new node(4);
node* root_left=new node(1);
node* root_right=new node(2);
root->left=root_left;
root->right=root_right;
}
int has_path_sum(node* root,int sum)
{
if (root==NULL)
{
return 0;
}
int d1=root->data + has_path_sum(root->left,sum);
int d2=root->data + has_path_sum(root->right,sum);
if(d1==sum || d2==sum)
{
return 1;
}
else
{
return 0;
}

}
int main()
{
node* wow=build();
bool result=has_path_sum(wow,6);
cout<<result;
return 0;
}

what mistake i am commiting in this problem.

Hey @shubhamssj5.ss
The return type of your build function is node*, and you’re not returning anything, Include a statement at the end of this function- return root;

but after correcting I am still getting wrong ans.
please correct it logically it has to check that any root to leaf is having the sum given returns true or false.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.