-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathSolution101.java
More file actions
40 lines (31 loc) · 785 Bytes
/
Solution101.java
File metadata and controls
40 lines (31 loc) · 785 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
package algorithm.leetcode;
/**
* @author: mayuan
* @desc: 对称二叉树
* @date: 2019/02/26
*/
public class Solution101 {
public boolean isSymmetric(TreeNode root) {
if (null == root) {
return true;
}
return isSymmetric(root.left, root.right);
}
public boolean isSymmetric(TreeNode left, TreeNode right) {
if (null == left || null == right) {
return left == right;
}
if (left.val != right.val){
return false;
}
return isSymmetric(left.left, right.right) && isSymmetric(left.right, right.left);
}
public class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode(int x) {
val = x;
}
}
}