In this problem,Nodes with duplicate values are not present.
class Solution {
public boolean flipEquiv(TreeNode root1, TreeNode root2) {
if (root1 == root2)
return true;
if (root1 == null || root2 == null || root1.val != root2.val)
return false;
return (flipEquiv(root1.left, root2.left) && flipEquiv(root1.right, root2.right) ||
flipEquiv(root1.left, root2.right) && flipEquiv(root1.right, root2.left));
}
}
What would be the time complexity of this code if node with duplicate values were also present??
How Can I improve my code so that it also works with duplicate values?
Thanks in Advance:)