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
- Decision Tree
- Tree Compass
- A - Distance in Tree
- DSU on Tree
- Rebuild TreeRebuild
- 01 Tree
- 【MySQL(1)| B-tree和B+tree】MySql
- 多路查詢樹:B-tree/b+tree
- LeetCode#110.Balanced Binary Tree(Tree/Height/DFS/Recursion)LeetCode
- Root of AVL Tree
- Tree – Information TheoryORM
- mvn dependency:tree
- Traversals of binary tree
- Circular Spanning Tree
- B-tree
- B+tree
- segment tree beats
- tree-shaking
- Walking the File Tree
- Causal Inference理論學習篇-Tree Based-Causal Tree
- LeetCode C++ 968. Binary Tree Cameras【Tree/DFS】困難LeetCodeC++
- Trie tree實踐
- 100-Same Tree
- B-tree索引索引
- el-tree-select
- 100. Same Tree
- [leetcode]same-treeLeetCode
- Leetcode Binary Tree PathsLeetCode
- F - Perfect Matching on a Tree
- tmp dbg parse tree
- 高效能Mysql 入門到放棄 之 B+-Tree (與B-Tree以及Binary Tree的對比解析)MySql
- 迴歸樹(Regression Tree)
- [LintCode] Check Full Binary Tree
- 翻譯:Linux and the Device TreeLinuxdev
- Webpack Tree shaking 深入探究Web
- Linux:-bash: tree: command not foundLinux
- 257-Binary Tree Paths