Time Complexity of LeetCode Problem 951

Revision en1, by R.A.N.K.A., 2020-09-03 20:15:34

Problem Link

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:)


  Rev. Lang. By When Δ Comment
en1 English R.A.N.K.A. 2020-09-03 20:15:34 828 Initial revision (published)