Thursday, November 17, 2011

Finding the path in a binary tree with given sum


public static boolean  hasPathSum(BinaryTree root, int sum){
if(root==null)
return(sum==0);
else
{
sum=sum-root.value;
return(hasPathSum(root.left,sum) || hasPathSum(root.right,sum));

}

}

No comments:

Post a Comment