package leetcode;

/**
 * https://leetcode.com/problems/flip-equivalent-binary-trees/
 */
public class Problem951 {
    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    public boolean flipEquiv(TreeNode root1, TreeNode root2) {
        // TODO
        return false;
    }

    public static void main(String[] args) {
        Problem951 prob = new Problem951();
        TreeNode root1 = new TreeNode(1);
        root1.left = new TreeNode(2);
        root1.left.left = new TreeNode(4);
        root1.left.right = new TreeNode(5);
        root1.left.right.left = new TreeNode(7);
        root1.left.right.right = new TreeNode(8);
        root1.right = new TreeNode(3);
        root1.right.left = new TreeNode(6);

        TreeNode root2 = new TreeNode(1);
        root2.left = new TreeNode(3);
        root2.left.right = new TreeNode(6);
        root2.right = new TreeNode(2);
        root2.right.left = new TreeNode(4);
        root2.right.right = new TreeNode(5);
        root2.right.right.left = new TreeNode(8);
        root2.right.right.right = new TreeNode(7);

        System.out.println(prob.flipEquiv(root1, root2)); // true
    }
}

@@ -348,16 +348,34 @@
     
-// TODO%0A
+if (root1 == root2) %7B%0A    
     
@@ -389,161 +389,130 @@
 urn 
-fals
+tru
 e;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem951 prob = new Problem951();%0A        TreeNode 
+%7D%0A        if ((root1 == null && root2 != null) %7C%7C%0A            (
 root1 
+!
 = n
-ew TreeNode(1);%0A
+ull && root2 == null) %7C%7C%0A  
         
 root
@@ -511,80 +511,73 @@
     
+  (
 root1.
-left = new TreeNode(2);%0A        root1.left.left = new TreeNode(4);
+val != root2.val)) %7B%0A            return false;%0A        %7D
 %0A   
@@ -573,32 +573,37 @@
       %7D%0A        
+if ((
 root1.left.right
@@ -600,33 +600,42 @@
 left
-.right = new TreeNode(5);
+ == null && root2.left != null) %7C%7C
 %0A   
@@ -631,32 +631,37 @@
 ull) %7C%7C%0A        
+    (
 root1.left.right
@@ -658,47 +658,54 @@
 left
-.right
+ != null && root2
 .left =
+=
  n
-ew TreeNode(7);%0A
+ull) %7C%7C%0A   
         
 root
@@ -696,24 +696,26 @@
 %0A           
+ (
 root1.left.r
@@ -716,212 +716,129 @@
 left
-.right.right = new TreeNode(8);%0A       
+ != null &&
  root
-1
+2
 .right
- = new TreeNode(3);%0A        root1.right.left = new TreeNode(6);%0A%0A        TreeNode root2 = new TreeNode(1);%0A       
+!= null && root1.left.val != root2.left.val)) %7B%0A            TreeNode tmp =
  root
-2
+1
 .left
- = new TreeNode(3);%0A
+;%0A   
         
 root
@@ -837,83 +837,39 @@
     
+ 
 root
-2
+1
 .left
-.right = new TreeNode(6);%0A      
  
+=
  root
-2
+1
 .right
- = new TreeNode(2);%0A
+;%0A    
     
@@ -880,219 +880,85 @@
 root
-2
+1
 .right
-.left = new TreeNode(4);%0A        root2.right.right = new TreeNode(5);%0A        root2.right.right.left = new TreeNode(8);%0A        root2.right.right.right = new TreeNode(7);%0A%0A        System.out.println(prob.
+ = tmp;%0A        %7D%0A        return flipEquiv(root1.left, root2.left) && 
 flip
@@ -972,26 +972,29 @@
 oot1
+.right
 , root2
-)); // true
+.right);
 %0A   

Solve problem 951