File tree Expand file tree Collapse file tree 1 file changed +7
-44
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +7
-44
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import com .fishercoder .common .classes .TreeNode ;
4
4
5
- /**
6
- * 100. Same Tree
7
- *
8
- * Given two binary trees, write a function to check if they are equal or not. Two binary trees are
9
- * considered equal if they are structurally identical and the nodes have the same value.
10
- *
11
- * Example 1:
12
- *
13
- * Input: 1 1
14
- * / \ / \
15
- * 2 3 2 3
16
- *
17
- * [1,2,3], [1,2,3]
18
- *
19
- * Output: true
20
- *
21
- * Example 2:
22
- *
23
- * Input: 1 1
24
- * / \
25
- * 2 2
26
- *
27
- * [1,2], [1,null,2]
28
- *
29
- * Output: false
30
- *
31
- * Example 3:
32
- *
33
- * Input: 1 1
34
- * / \ / \
35
- * 2 1 1 2
36
- *
37
- * [1,2,1], [1,1,2]
38
- *
39
- * Output: false
40
- */
41
-
42
5
public class _100 {
43
- public static class Solution1 {
44
- public boolean isSameTree (TreeNode p , TreeNode q ) {
45
- if (p == null || q == null ) {
46
- return p == q ;
47
- }
48
- return p .val == q .val && isSameTree (p .left , q .left ) && isSameTree (p .right , q .right );
6
+ public static class Solution1 {
7
+ public boolean isSameTree (TreeNode p , TreeNode q ) {
8
+ if (p == null || q == null ) {
9
+ return p == q ;
10
+ }
11
+ return p .val == q .val && isSameTree (p .left , q .left ) && isSameTree (p .right , q .right );
12
+ }
49
13
}
50
- }
51
14
}
You can’t perform that action at this time.
0 commit comments