-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolutionJZ58.java
More file actions
43 lines (36 loc) · 843 Bytes
/
SolutionJZ58.java
File metadata and controls
43 lines (36 loc) · 843 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
33
34
35
36
37
38
39
40
41
42
43
package com.company;
public class SolutionJZ58 {
/*
递归
三种情况:
1.都为空:return true
2.一个为空或val不等:return false
3.进行递归
*/
boolean isSymmetrical(TreeNode pRoot) {
if(pRoot==null)
return true;
return check(pRoot.left,pRoot.right);
}
boolean check(TreeNode one,TreeNode two){
if(one==null&&two==null){
return true;
}
else if((one!=null)&&(two==null)||(one==null&&two!=null)||(one.val!=two.val)){
return false;
}
else {
return check(one.left,two.right)&&check(one.right,two.left);
}
}
}
/*
class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;
public TreeNode(int val) {
this.val = val;
}
}
*/