101-Symmetric Tree
Description
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
For example, this binary tree [1,2,2,3,4,4,3] is symmetric:
1
/ \
2 2
/ \ / \
3 4 4 3
But the following [1,2,2,null,3,null,3] is not:
1
/ \
2 2
\ \
3 3
問題描述
給定二叉樹, 判斷該樹是否圍繞中心對稱
問題分析
解法
class Solution {
public boolean isSymmetric(TreeNode root){
return root == null ? true : isMirror(root.left, root.right);
}
public boolean isMirror(TreeNode node1, TreeNode node2){
if(node1 == null && node2 == null) return true;
if(node1 == null || node2 == null) return false;
return node1.val == node2.val && isMirror(node1.left,node2.right) && isMirror(node1.right, node2.left);
}
}
相關文章
- tree
- DSU on Tree
- Rebuild TreeRebuild
- 01 Tree
- Tree Compass
- A - Distance in Tree
- Decision Tree
- 【MySQL(1)| B-tree和B+tree】MySql
- 多路查詢樹:B-tree/b+tree
- LeetCode#110.Balanced Binary Tree(Tree/Height/DFS/Recursion)LeetCode
- segment tree beats
- Circular Spanning Tree
- B-tree
- B+tree
- tree-shaking
- Walking the File Tree
- Root of AVL Tree
- Tree – Information TheoryORM
- mvn dependency:tree
- Traversals of binary tree
- Causal Inference理論學習篇-Tree Based-Causal Tree
- LeetCode C++ 968. Binary Tree Cameras【Tree/DFS】困難LeetCodeC++
- F - Perfect Matching on a Tree
- tmp dbg parse tree
- el-tree-select
- 100. Same Tree
- [leetcode]same-treeLeetCode
- Leetcode Binary Tree PathsLeetCode
- Trie tree實踐
- 100-Same Tree
- B-tree索引索引
- 高效能Mysql 入門到放棄 之 B+-Tree (與B-Tree以及Binary Tree的對比解析)MySql
- 「CF1017G」The Tree
- [LintCode] Binary Tree Level Order
- Leetcode 100. Same TreeLeetCode
- 545. Boundary of Binary Tree
- 257. Binary Tree Paths
- 簡述LSM-Tree