File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 25
25
26
26
| #| Title| Tag| Date|
27
27
| :-:| :-:| :-:| :-:|
28
+ | 6| [ 101. 对称二叉树] ( https://github.com/Doragd/Algorithm/issues/6 ) | ` 二叉树 ` ` 递归 ` | 2023-12-16T02:01:21Z|
28
29
| 3| [ 100. 相同的树] ( https://github.com/Doragd/Algorithm/issues/3 ) | ` 二叉树 ` ` 递归 ` | 2023-12-10T12:14:09Z|
29
30
| 2| [ 110. 平衡二叉树] ( https://github.com/Doragd/Algorithm/issues/2 ) | ` 二叉树 ` ` 递归 ` | 2023-12-10T10:56:53Z|
Original file line number Diff line number Diff line change
1
+ # 101. 对称二叉树
2
+
3
+ * [ 101. 对称二叉树] ( https://leetcode-cn.com/problems/symmetric-tree/ )
4
+ - 给你一个二叉树的根节点 ` root ` , 检查它是否轴对称。
5
+ - 递归遍历+问题分解+分类讨论
6
+ - 子结构: 两棵小树p和q, 同步遍历两棵树
7
+ - 终止条件:p和q其中一方为空 或者 p 和 q不相等 return false
8
+ - 否则: 递归判定: (左子树,右子树) (右子树,左子树)
9
+ ``` C++
10
+ class Solution {
11
+ public:
12
+ //递归遍历+分类讨论:
13
+ //子结构: 两棵小树p和q, 同步遍历两棵树
14
+ //p和q其中一方为空 或者 p 和 q不相等 return false
15
+ //否则: 递归判定: (左子树,右子树) (右子树,左子树)
16
+ bool dfs(TreeNode * p, TreeNode * q){
17
+ if(!p && !q) return true;
18
+ if(p && q && p->val == q->val) return dfs(p->left, q->right) && dfs(p->right, q->left);
19
+ return false;
20
+ }
21
+ bool isSymmetric(TreeNode* root) {
22
+ if(!root) return true;
23
+ return dfs(root->left, root->right);
24
+ }
25
+ };
26
+ ```
27
+
28
+ ---
29
+
30
+ * Link: https://github.com/Doragd/Algorithm/issues/6
31
+ * Labels: `二叉树`, `递归`
32
+ * Creation Date: 2023-12-16T02:01:21Z
You can’t perform that action at this time.
0 commit comments