- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem101.java
More file actions
Latest commit
22 lines (20 loc) · 667 Bytes
/
Copy pathProblem101.java
File metadata and controls
22 lines (20 loc) · 667 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
classProblem101 {
publicstaticvoidmain(String[] args) {
Problem101p = newProblem101();
TreeNoderoot = newTreeNode(1);
root.left = newTreeNode(2);
System.out.println(p.isSymmetric(root));
}
publicbooleanisSymmetric(TreeNoderoot) {
if (root == null) returntrue;
returnisSame(root.left, root.right);
}
booleanisSame(TreeNodep, TreeNodeq) {
if (p == null && q == null) returntrue;
if (p == null || q == null) returnfalse;
if (p.val == q.val) {
returnisSame(p.left, q.right) && isSame(p.right, q.left);
}
returnfalse;
}
}