Scribblings
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
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment