forked from JsonChao/Awesome-Algorithm-Study
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution101.java
More file actions
32 lines (27 loc) · 745 Bytes
/
Copy pathSolution101.java
File metadata and controls
32 lines (27 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package binary_search_tree_problem;
public class Solution101 {
public static class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode(int x) { val = x; }
}
public boolean isSymmetric(TreeNode root) {
if (root == null) {
return true;
}
return isSymmetric(root.left, root.right);
}
private boolean isSymmetric(TreeNode l1, TreeNode l2) {
if (l1 == null && l2 == null) {
return true;
}
if (l1 == null || l2 == null) {
return false;
}
if (l1.val != l2.val) {
return false;
}
return isSymmetric(l1.left, l2.right) && isSymmetric(l1.right, l2.left);
}
}