File tree 2 files changed +18
-1
lines changed
2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -311,7 +311,7 @@ LeetCode
311
311
| 104| [ Maximum Depth of Binary Tree] ( https://leetcode.com/problems/maximum-depth-of-binary-tree/ ) | | Easy|
312
312
| 103| [ Binary Tree Zigzag Level Order Traversal] ( https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/ ) | | Medium|
313
313
| 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|
315
315
| 100| [ Same Tree] ( https://leetcode.com/problems/same-tree/ ) | | Easy|
316
316
| 99| [ Recover Binary Search Tree] ( https://leetcode.com/problems/recover-binary-search-tree/ ) | | Hard|
317
317
| 98| [ Validate Binary Search Tree] ( https://leetcode.com/problems/validate-binary-search-tree/ ) | | Medium|
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments