Q. Write a function that takes two trees as an argument and returns true if they are equal.
Anonymous
Traversal list won't work from comparing one traversal alone. It is possible for different trees to produce the same list in a tree order traversal. Even if it did work producing a list would be unnecessary. Boolean isEqual(t1, t2){ If( both null){ Return true; } if (t1.val != t2.val){ Return false; } Return isEqual(t1.left,t2.left) && isEqual(t1.right,t2.right); }
Check out your Company Bowl for anonymous work chats.