class Tree {
/*you are required to complete this function */
static int s=0;
boolean hasPathSum(Node node, int sum)
{
if(node == null)
return false;
s=s+node.data;
if(s==sum)
{
// System.out.println(“jadhc”);
return true;
}
// System.out.println(s);
if(s>sum)
{
s=s-node.data;
// System.out.println(s);
return false;
}
if(s==sum)
return true;
boolean l = hasPathSum(node.left,sum);
boolean r = hasPathSum(node.right,sum);
if(l==false && r==false){
s=s-node.data;
// System.out.println(s);}
return false;
}
}