How can the trees be different if the string is same. In this question i have taken input a string and compared them. If they’re same then printed true, otherwise printed false. 3 test cases passed, 1 failed.
Here is the code.
Structurally Identical
You are supposed to do this by trees only. First build both trees and then compare their data values, dont use string as it is wrong approach.
I have made the changes. I constructed two different trees and stored their inorder traversals in two vectors and compared each element of both vectors. Still getting wrong answer in one test case.
After building a tree, you are supposed to make a bool function which will work on following conditions :: bool isIdentical(node *root1, node *root2)
{
if(root1==NULL && root2==NULL)
{
return true;
}
else
if(root1==NULL || root2==NULL)
{
return false;
}
else
{
return (isIdentical(root1->left,root2->left) && isIdentical(root1->right,root2->right));
}
}
Modify your code and then try to submit
1 Like