Skip to content

Commit 93df943

Browse files
committed
update new record
1 parent 2ff27c3 commit 93df943

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525

2626
|#|Title|Tag|Date|
2727
|:-:|:-:|:-:|:-:|
28+
|6|[101. 对称二叉树](https://github.com/Doragd/Algorithm/issues/6)|`二叉树` `递归`|2023-12-16T02:01:21Z|
2829
|3|[100. 相同的树](https://github.com/Doragd/Algorithm/issues/3)|`二叉树` `递归`|2023-12-10T12:14:09Z|
2930
|2|[110. 平衡二叉树](https://github.com/Doragd/Algorithm/issues/2)|`二叉树` `递归`|2023-12-10T10:56:53Z|

backup/6#101. 对称二叉树.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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

0 commit comments

Comments
 (0)