Skip to content

Commit ea9b352

Browse files
committed
Solution to write a Program to check if two trees are identical
1 parent 1444da0 commit ea9b352

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/Trees/Trees.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,15 @@ static ArrayList<Integer> postorderTraversal(TreeNode A, ArrayList<Integer> list
5050

5151
return list;
5252
}
53+
54+
static int isSameTree(TreeNode A, TreeNode B) {
55+
56+
if (A == null && B == null){return 1;}
57+
if (A == null || B == null){return 0;}
58+
59+
if ((A.val == B.val) && (isSameTree(A.left,B.left) == 1) && (isSameTree(A.right,B.right) == 1)){
60+
return 1;
61+
}
62+
return 0;
63+
}
5364
}

0 commit comments

Comments
 (0)