Skip to content

Commit c0f15fe

Browse files
committed
101. 对称二叉树
1 parent 652f0c1 commit c0f15fe

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/com/gatsby/_101SymmetricTree.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.gatsby;
2+
3+
/**
4+
* @ClassName: _101SymmetricTree
5+
* @Description: leetcode 101 对称二叉树
6+
* @author: Gatsby
7+
* @date: 2022/5/15 20:03
8+
*/
9+
10+
public class _101SymmetricTree {
11+
private boolean isSymmetric(TreeNode left, TreeNode right) {
12+
if (left == null && right == null) return true;
13+
if (left != null || right != null) return false;
14+
if (left.val != right.val) return false;
15+
16+
return isSymmetric(left.right, right.left) && isSymmetric(right.left, left.right);
17+
}
18+
19+
public boolean isSymmetric(TreeNode root) {
20+
if (root == null) return true;
21+
22+
return isSymmetric(root.left, root.right);
23+
}
24+
}
25+
26+

0 commit comments

Comments
 (0)