Skip to content

Commit 61631e8

Browse files
add java solution for leetcode 101
1 parent f1479bc commit 61631e8

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ LeetCode
311311
|104|[Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/)| |Easy|
312312
|103|[Binary Tree Zigzag Level Order Traversal](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/)| |Medium|
313313
|102|[Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal/)| |Easy|
314-
|101|[Symmetric Tree](https://leetcode.com/problems/symmetric-tree/)| |Easy|
314+
|101|[Symmetric Tree](https://leetcode.com/problems/symmetric-tree/)| [java](./algorithms/sysmetricTree/Solution.java) |Easy|
315315
|100|[Same Tree](https://leetcode.com/problems/same-tree/)| |Easy|
316316
|99|[Recover Binary Search Tree](https://leetcode.com/problems/recover-binary-search-tree/)| |Hard|
317317
|98|[Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree/)| |Medium|
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class Solution {
2+
//从上向下递归,检验镜像树
3+
public boolean isSymmetric(TreeNode root) {
4+
if(null == root){
5+
return true;
6+
}
7+
return isMirror(root.left, root.right);
8+
}
9+
10+
private boolean isMirror(TreeNode left, TreeNode right){
11+
if(left == null && right == null) return true;
12+
if(left == null || right == null) return false;
13+
return (left.val == right.val)
14+
&& isMirror(left.left, right.right)
15+
&& isMirror(left.right, right.left) ;
16+
}
17+
}

0 commit comments

Comments
 (0)