forked from DreamCats/java-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathT2.java
More file actions
33 lines (30 loc) · 686 Bytes
/
Copy pathT2.java
File metadata and controls
33 lines (30 loc) · 686 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
/**
* @program JavaBooks
* @description: 对称二叉树
* @author: mf
* @create: 2020/03/09 13:28
*/
package subject.tree;
/**
* 1
* / \
* 2 2
* / \ / \
* 3 4 4 3
*/
public class T2 {
/**
* 还是前序递归
* @param root
* @return
*/
public boolean isSymmetric(TreeNode root) {
return isSym(root, root);
}
public boolean isSym(TreeNode root, TreeNode root1) {
if (root == null && root1 == null) return true;
if (root == null || root1 == null) return false;
if (root.val != root1.val) return false;
return isSym(root.left, root1. right) && isSym(root.right, root1.left);
}
}