-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprblm101.java
More file actions
24 lines (21 loc) · 789 Bytes
/
prblm101.java
File metadata and controls
24 lines (21 loc) · 789 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
public class prblm101 {
public static void main(String[] args) {
TreeNode root = new TreeNode(1);
root.left = new TreeNode(2);
root.right = new TreeNode(2);
root.left.left = new TreeNode(3);
root.left.right = new TreeNode(4);
root.right.left = new TreeNode(4);
root.right.right = new TreeNode(3);
System.out.println(new prblm101().isSymmetric(root));
}
public boolean isSymmetric(TreeNode root) {
return solve(root.left, root.right);
}
public boolean solve(TreeNode p, TreeNode q) {
if(p == null && q == null) return true;
if(p == null || q == null) return false;
if(p.val != q.val) return false;
return solve(p.left, q.right) && solve(p.right, q.left);
}
}