We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ef23e2b commit f7fc946Copy full SHA for f7fc946
EASY/src/easy/SameTree.java
@@ -0,0 +1,21 @@
1
+package easy;
2
+
3
+import classes.TreeNode;
4
5
+/**100. Same Tree
6
7
+ Total Accepted: 145623
8
+ Total Submissions: 330537
9
+ Difficulty: Easy
10
11
+Given two binary trees, write a function to check if they are equal or not.
12
13
+Two binary trees are considered equal if they are structurally identical and the nodes have the same value. */
14
+public class SameTree {
15
+ //recursion idea flows out naturally.
16
+ public boolean isSameTree(TreeNode p, TreeNode q) {
17
+ if(p == null || q == null) return p == q;
18
+ if(p.val != q.val) return false;
19
+ return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
20
+ }
21
+}
0 commit comments