Skip to content

Commit 3e76332

Browse files
refactor 100
1 parent fb8d00d commit 3e76332

File tree

1 file changed

+7
-44
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+7
-44
lines changed

src/main/java/com/fishercoder/solutions/_100.java

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,13 @@
22

33
import com.fishercoder.common.classes.TreeNode;
44

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-
425
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+
}
4913
}
50-
}
5114
}

0 commit comments

Comments
 (0)