Solution #1: Here is the recursive code,
int hasSum(struct node* root, int sum)
{
if(root == NULL)
return (sum == 0);
sum = sum - root->data;
return hasSum(root->left, sum) || hasSum(root->right, sum);
}
No comments:
Post a Comment