@Test void testIsSame() { IntegerNode sameAsRoot = newBinaryTree(); assertThat(isSame(ROOT, sameAsRoot)).isTrue(); IntegerNode five = IntegerNode.builder() .value(5) .build(); IntegerNode three = IntegerNode.builder() .left(five) .value(3) .build(); IntegerNode six = IntegerNode.builder() .value(6) .build(); IntegerNode fifteen = IntegerNode.builder() .left(three) .right(six) .value(15) .build(); assertThat(isSame(ROOT, fifteen)).isFalse(); }
public static boolean isSame(IntegerNode root1, IntegerNode root2) { boolean same = false; if (root1 == root2) { same = true; } else if (root1 != null && root2 != null && root1.value() == root2.value()) { same = isSame(root1.left(), root2.left()) && isSame(root1.right(), root2.right()); } return same; }
BinaryTreeUtil { public static boolean isSame(IntegerNode root1, IntegerNode root2) { boolean same = false; if (root1 == root2) { same = true; } else if (root1 != null && root2 != null && root1.value() == root2.value()) { same = isSame(root1.left(), root2.left()) && isSame(root1.right(), root2.right()); } return same; } }
BinaryTreeUtil { public static boolean isSame(IntegerNode root1, IntegerNode root2) { boolean same = false; if (root1 == root2) { same = true; } else if (root1 != null && root2 != null && root1.value() == root2.value()) { same = isSame(root1.left(), root2.left()) && isSame(root1.right(), root2.right()); } return same; } private  BinaryTreeUtil(); }
BinaryTreeUtil { public static boolean isSame(IntegerNode root1, IntegerNode root2) { boolean same = false; if (root1 == root2) { same = true; } else if (root1 != null && root2 != null && root1.value() == root2.value()) { same = isSame(root1.left(), root2.left()) && isSame(root1.right(), root2.right()); } return same; } private  BinaryTreeUtil(); static int height(IntegerNode root); static boolean isBST(ParentAwareIntegerNode root); static boolean isSame(IntegerNode root1, IntegerNode root2); static IntegerNode lowestCommonAncestor(IntegerNode root, int value1, int value2); }
BinaryTreeUtil { public static boolean isSame(IntegerNode root1, IntegerNode root2) { boolean same = false; if (root1 == root2) { same = true; } else if (root1 != null && root2 != null && root1.value() == root2.value()) { same = isSame(root1.left(), root2.left()) && isSame(root1.right(), root2.right()); } return same; } private  BinaryTreeUtil(); static int height(IntegerNode root); static boolean isBST(ParentAwareIntegerNode root); static boolean isSame(IntegerNode root1, IntegerNode root2); static IntegerNode lowestCommonAncestor(IntegerNode root, int value1, int value2);  }