(s2_len + 1));
+ dp[0][0] = true;
+ for (int i = 0; i <= s1_len; i++)
+ {
+ for (int j = 0; j <= s2_len; j++)
+ {
+ if (dp[i][j])
+ {
+ if (i < s1_len && s1[i] == s3[i + j])
+ dp[i + 1][j] = true;
+ if (j < s2_len && s2[j] == s3[i + j])
+ dp[i][j + 1] = true;
+ }
+ }
+ }
+ return dp[s1_len][s2_len];
+ }
+};
+```
diff --git "a/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/98_\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/config.json" "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/98_\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/config.json"
new file mode 100644
index 0000000000000000000000000000000000000000..1e7348c90e3ee1c5d5f8302e35bce191c43e2225
--- /dev/null
+++ "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/98_\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/config.json"
@@ -0,0 +1,12 @@
+{
+ "node_id": "569d5e11c4fc5de7844053d9a733c5e8",
+ "keywords": [
+ "leetcode",
+ "恢复二叉搜索树"
+ ],
+ "children": [],
+ "export": [
+ "solution.json"
+ ],
+ "title": "恢复二叉搜索树"
+}
\ No newline at end of file
diff --git "a/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/98_\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/desc.html" "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/98_\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/desc.html"
new file mode 100644
index 0000000000000000000000000000000000000000..a4c049d29c48dfe44b2a5c28e856712880ea4353
--- /dev/null
+++ "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/98_\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/desc.html"
@@ -0,0 +1 @@
+给你二叉搜索树的根节点 root
,该树中的两个节点被错误地交换。请在不改变其结构的情况下,恢复这棵树。
进阶:使用 O(n) 空间复杂度的解法很容易实现。你能想出一个只使用常数空间的解决方案吗?
示例 1:

输入:root = [1,3,null,null,2]
输出:[3,1,null,null,2]
解释:3 不能是 1 左孩子,因为 3 > 1 。交换 1 和 3 使二叉搜索树有效。
示例 2:

输入:root = [3,1,4,null,null,2]
输出:[2,1,4,null,null,3]
解释:2 不能在 3 的右子树中,因为 2 < 3 。交换 2 和 3 使二叉搜索树有效。
提示:
- 树上节点的数目在范围
[2, 1000]
内 -231 <= Node.val <= 231 - 1
\ No newline at end of file
diff --git "a/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/98_\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/solution.cpp" "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/98_\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/solution.cpp"
new file mode 100644
index 0000000000000000000000000000000000000000..9a885cee574a7664ea0fc3b4604f332ddc5d38c0
--- /dev/null
+++ "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/98_\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/solution.cpp"
@@ -0,0 +1,49 @@
+#include
+using namespace std;
+struct TreeNode
+{
+ int val;
+ TreeNode *left;
+ TreeNode *right;
+ TreeNode() : val(0), left(nullptr), right(nullptr) {}
+ TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
+ TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
+};
+class Solution
+{
+public:
+ void recoverTree(TreeNode *root)
+ {
+ dfs(root);
+ int tmp = p0_->val;
+ p0_->val = p1_->val;
+ p1_->val = tmp;
+ }
+private:
+ int wrong_ = 0;
+ TreeNode *prev_ = nullptr;
+ TreeNode *p0_ = nullptr;
+ TreeNode *p1_ = nullptr;
+ void dfs(TreeNode *root)
+ {
+ if (root == nullptr || wrong_ == 2)
+ {
+ return;
+ }
+ dfs(root->left);
+ if (prev_ != nullptr && prev_->val > root->val)
+ {
+ if (++wrong_ == 1)
+ {
+ p0_ = prev_;
+ p1_ = root;
+ }
+ else if (wrong_ == 2)
+ {
+ p1_ = root;
+ }
+ }
+ prev_ = root;
+ dfs(root->right);
+ }
+};
\ No newline at end of file
diff --git "a/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/98_\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/solution.json" "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/98_\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/solution.json"
new file mode 100644
index 0000000000000000000000000000000000000000..c2dc9be962f6bc732180aa682dbee1b0154f9f76
--- /dev/null
+++ "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/98_\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/solution.json"
@@ -0,0 +1,6 @@
+{
+ "type": "code_options",
+ "author": "CSDN.net",
+ "source": "solution.md",
+ "exercise_id": "6f36dd5736a941d091ed802411238645"
+}
\ No newline at end of file
diff --git "a/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/98_\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/solution.md" "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/98_\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/solution.md"
new file mode 100644
index 0000000000000000000000000000000000000000..a6c4158b758a9622e727312bb9c5df7c43af088a
--- /dev/null
+++ "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/98_\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/solution.md"
@@ -0,0 +1,190 @@
+# 恢复二叉搜索树
+给你二叉搜索树的根节点 root
,该树中的两个节点被错误地交换。请在不改变其结构的情况下,恢复这棵树。
进阶:使用 O(n) 空间复杂度的解法很容易实现。你能想出一个只使用常数空间的解决方案吗?
示例 1:

输入:root = [1,3,null,null,2]
输出:[3,1,null,null,2]
解释:3 不能是 1 左孩子,因为 3 > 1 。交换 1 和 3 使二叉搜索树有效。
示例 2:

输入:root = [3,1,4,null,null,2]
输出:[2,1,4,null,null,3]
解释:2 不能在 3 的右子树中,因为 2 < 3 。交换 2 和 3 使二叉搜索树有效。
提示:
- 树上节点的数目在范围
[2, 1000]
内 -231 <= Node.val <= 231 - 1
+以下错误的选项是?
+## aop
+### before
+```cpp
+#include
+using namespace std;
+
+struct TreeNode
+{
+ int val;
+ TreeNode *left;
+ TreeNode *right;
+ TreeNode() : val(0), left(nullptr), right(nullptr) {}
+ TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
+ TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
+};
+```
+### after
+```cpp
+
+```
+
+## 答案
+```cpp
+class Solution
+{
+public:
+ TreeNode *pre = NULL;
+ TreeNode *one = NULL;
+ TreeNode *two = NULL;
+ bool search(TreeNode *root)
+ {
+ if (root == NULL)
+ return false;
+ if (search(root->left))
+ return true;
+ if (pre != NULL && pre->val > root->val)
+ {
+ if (one == NULL)
+ {
+ one = root;
+ two = pre;
+ }
+ else
+ {
+ two = root;
+ return true;
+ }
+ }
+ pre = root;
+ if (search(root->right))
+ return true;
+ return false;
+ }
+ void recoverTree(TreeNode *root)
+ {
+ search(root);
+ swap(one->val, two->val);
+ }
+};
+```
+## 选项
+
+### A
+```cpp
+class Solution
+{
+public:
+ TreeNode *x, *y, *pre;
+ void DFS(TreeNode *root)
+ {
+ if (root == nullptr)
+ return;
+ DFS(root->left);
+ if (pre && root->val < pre->val)
+ {
+ x = root;
+ if (!y)
+ y = pre;
+ else
+ return;
+ }
+ pre = root;
+ DFS(root->right);
+ }
+ void recoverTree(TreeNode *root)
+ {
+ DFS(root);
+ swap(x->val, y->val);
+ }
+};
+```
+
+### B
+```cpp
+class Solution
+{
+public:
+ void insert(int val, vector &vals)
+ {
+ if (vals.size() > 0)
+ {
+ for (int i = 0; i < vals.size(); i++)
+ {
+ if (val < vals[i])
+ {
+ vals.insert(vals.begin() + i, val);
+ return;
+ }
+ }
+ }
+ vals.push_back(val);
+ }
+ void recoverTree(TreeNode *root)
+ {
+ stack s;
+ vector vals;
+ TreeNode *tem = root;
+ while (tem || !s.empty())
+ {
+ while (tem)
+ {
+ s.push(tem);
+ tem = tem->left;
+ }
+ if (!s.empty())
+ {
+ tem = s.top();
+ s.pop();
+ insert(tem->val, vals);
+ tem = tem->right;
+ }
+ }
+ tem = root;
+ int j = 0;
+ while (tem || !s.empty())
+ {
+ while (tem)
+ {
+ s.push(tem);
+ tem = tem->left;
+ }
+ if (!s.empty())
+ {
+ tem = s.top();
+ s.pop();
+ tem->val = vals[j++];
+ tem = tem->right;
+ }
+ }
+ }
+};
+```
+
+### C
+```cpp
+class Solution
+{
+public:
+ vector order;
+ void inOrder(TreeNode *root)
+ {
+ if (root->left)
+ inOrder(root->left);
+ order.push_back(root);
+ if (root->right)
+ inOrder(root->right);
+ }
+ void recoverTree(TreeNode *root)
+ {
+ inOrder(root);
+ int left = -1, right = -1;
+ for (int i = 0; i < order.size() - 1; ++i)
+ {
+ if (order[i]->val > order[i + 1]->val)
+ {
+ if (left == -1)
+ left = i;
+ right = i + 1;
+ }
+ }
+ if (right == -1)
+ swap(order[left]->val, order[left + 1]->val);
+ else
+ swap(order[left]->val, order[right]->val);
+ }
+};
+```
diff --git "a/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/99_\347\233\270\345\220\214\347\232\204\346\240\221/config.json" "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/99_\347\233\270\345\220\214\347\232\204\346\240\221/config.json"
new file mode 100644
index 0000000000000000000000000000000000000000..36f471b825d9ffff868d4375868fa44e807f3b25
--- /dev/null
+++ "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/99_\347\233\270\345\220\214\347\232\204\346\240\221/config.json"
@@ -0,0 +1,12 @@
+{
+ "node_id": "569d5e11c4fc5de7844053d9a733c5e8",
+ "keywords": [
+ "leetcode",
+ "相同的树"
+ ],
+ "children": [],
+ "export": [
+ "solution.json"
+ ],
+ "title": "相同的树"
+}
\ No newline at end of file
diff --git "a/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/99_\347\233\270\345\220\214\347\232\204\346\240\221/desc.html" "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/99_\347\233\270\345\220\214\347\232\204\346\240\221/desc.html"
new file mode 100644
index 0000000000000000000000000000000000000000..2d8a4c0029cd3168cf01d57a2c8e65b6c71649ae
--- /dev/null
+++ "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/99_\347\233\270\345\220\214\347\232\204\346\240\221/desc.html"
@@ -0,0 +1 @@
+给你两棵二叉树的根节点 p
和 q
,编写一个函数来检验这两棵树是否相同。
如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的。
示例 1:

输入:p = [1,2,3], q = [1,2,3]
输出:true
示例 2:

输入:p = [1,2], q = [1,null,2]
输出:false
示例 3:

输入:p = [1,2,1], q = [1,1,2]
输出:false
提示:
- 两棵树上的节点数目都在范围
[0, 100]
内 -104 <= Node.val <= 104
\ No newline at end of file
diff --git "a/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/99_\347\233\270\345\220\214\347\232\204\346\240\221/solution.cpp" "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/99_\347\233\270\345\220\214\347\232\204\346\240\221/solution.cpp"
new file mode 100644
index 0000000000000000000000000000000000000000..d465336018a8577aa7e9e889e1e3f8876d0eb484
--- /dev/null
+++ "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/99_\347\233\270\345\220\214\347\232\204\346\240\221/solution.cpp"
@@ -0,0 +1,31 @@
+#include
+using namespace std;
+struct TreeNode
+{
+ int val;
+ TreeNode *left;
+ TreeNode *right;
+ TreeNode() : val(0), left(nullptr), right(nullptr) {}
+ TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
+ TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
+};
+class Solution
+{
+public:
+ bool isSameTree(TreeNode *p, TreeNode *q)
+ {
+ if (p == nullptr && q == nullptr)
+ {
+ return true;
+ }
+ if (p == nullptr || q == nullptr)
+ {
+ return false;
+ }
+ if (p->val != q->val)
+ {
+ return false;
+ }
+ return isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
+ }
+};
\ No newline at end of file
diff --git "a/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/99_\347\233\270\345\220\214\347\232\204\346\240\221/solution.json" "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/99_\347\233\270\345\220\214\347\232\204\346\240\221/solution.json"
new file mode 100644
index 0000000000000000000000000000000000000000..c6382daa809df6a4f4a1042630cb5229b44496f0
--- /dev/null
+++ "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/99_\347\233\270\345\220\214\347\232\204\346\240\221/solution.json"
@@ -0,0 +1,6 @@
+{
+ "type": "code_options",
+ "author": "CSDN.net",
+ "source": "solution.md",
+ "exercise_id": "0f00b8981cd541598110de5d1445d8f6"
+}
\ No newline at end of file
diff --git "a/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/99_\347\233\270\345\220\214\347\232\204\346\240\221/solution.md" "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/99_\347\233\270\345\220\214\347\232\204\346\240\221/solution.md"
new file mode 100644
index 0000000000000000000000000000000000000000..c58f0f3ecb4ff5179e5bf047974b64c14be21eb9
--- /dev/null
+++ "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\346\240\221/99_\347\233\270\345\220\214\347\232\204\346\240\221/solution.md"
@@ -0,0 +1,90 @@
+# 相同的树
+给你两棵二叉树的根节点 p
和 q
,编写一个函数来检验这两棵树是否相同。
如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的。
示例 1:

输入:p = [1,2,3], q = [1,2,3]
输出:true
示例 2:

输入:p = [1,2], q = [1,null,2]
输出:false
示例 3:

输入:p = [1,2,1], q = [1,1,2]
输出:false
提示:
- 两棵树上的节点数目都在范围
[0, 100]
内 -104 <= Node.val <= 104
+以下错误的选项是?
+## aop
+### before
+```cpp
+#include
+using namespace std;
+
+struct TreeNode
+{
+ int val;
+ TreeNode *left;
+ TreeNode *right;
+ TreeNode() : val(0), left(nullptr), right(nullptr) {}
+ TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
+ TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
+};
+
+```
+### after
+```cpp
+
+```
+
+## 答案
+```cpp
+都是错的
+```
+## 选项
+
+### A
+```cpp
+class Solution
+{
+public:
+ bool isSameTree(TreeNode *p, TreeNode *q)
+ {
+ if (p == nullptr)
+ return q == nullptr;
+ return q != nullptr && p->val == q->val && isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
+ }
+};
+```
+
+### B
+```cpp
+class Solution
+{
+public:
+ bool isSameTree(TreeNode *p, TreeNode *q)
+ {
+ TreeNode *temp, *temq;
+ temp = p;
+ temq = q;
+ bool lb, rb;
+ if (!p && !q)
+ return true;
+ if ((!p || !q) || p->val != q->val)
+ return false;
+ else
+ {
+ lb = isSameTree(p->left, q->left);
+ rb = isSameTree(p->right, q->right);
+ }
+ if (lb && rb)
+ return true;
+ else
+ return false;
+ }
+};
+```
+
+### C
+```cpp
+class Solution
+{
+public:
+ bool isSameTree(TreeNode *p, TreeNode *q)
+ {
+ if (p == NULL && q == NULL)
+ return true;
+ if (p == NULL || q == NULL)
+ return false;
+ if (p->val != q->val)
+ return false;
+ return (isSameTree(p->left, q->left) && isSameTree(p->right, q->right));
+ }
+};
+```
diff --git "a/data_backup/1.leetcode/96_\344\272\244\351\224\231\345\255\227\347\254\246\344\270\262/solution.md" "b/data_backup/1.leetcode/96_\344\272\244\351\224\231\345\255\227\347\254\246\344\270\262/solution.md"
index 5a075ca4c2e2379de9f7ebfcbf55be1d71d0f1be..c6bf37221b875b9c0c64306c012cfd97adc0615f 100644
--- "a/data_backup/1.leetcode/96_\344\272\244\351\224\231\345\255\227\347\254\246\344\270\262/solution.md"
+++ "b/data_backup/1.leetcode/96_\344\272\244\351\224\231\345\255\227\347\254\246\344\270\262/solution.md"
@@ -4,30 +4,155 @@
## aop
### before
```cpp
-
+#include
+using namespace std;
```
### after
```cpp
-
+int main()
+{
+ Solution sol;
+ bool res;
+ string s1 = "aabcc";
+ string s2 = "dbbca";
+ string s3 = "aadbbcbcac";
+ res = sol.isInterleave(s1, s2, s3);
+ cout << res;
+ return 0;
+}
```
## 答案
```cpp
+class Solution
+{
+public:
+ bool isInterleave(string s1, string s2, string s3)
+ {
+ int len1 = s1.length();
+ int len2 = s2.length();
+ int len3 = s3.length();
+
+ if (len1 + len2 != len3)
+ return false;
+
+ bool f[len1 + 1][len2 + 1];
+ f[0][0] = true;
+ for (int i = 0; i < len1 + 1; i++)
+ {
+ for (int j = 0; j < len2 + 1; j++)
+ {
+ if (j > 0)
+ {
+ f[i][j] = f[i][j - 1] && s3[i + j - 1];
+ }
+ if (i > 0)
+ {
+ f[i][j] = f[i][j] || (f[i - 1][j] && s3[i + j - 1]);
+ }
+ }
+ }
+ return f[len1][len2];
+ }
+};
```
## 选项
### A
```cpp
+class Solution
+{
+public:
+ bool isInterleave(string s1, string s2, string s3)
+ {
+ if (s1.size() + s2.size() != s3.size())
+ return false;
+ int m = s1.size(), n = s2.size(), i, j, k;
+ vector> dp(m + 1, vector(n + 1, 0));
+ dp[0][0] = 1;
+ for (i = 0; i < m; i++)
+ if (s1[i] == s3[i])
+ dp[i + 1][0] = 1;
+ else
+ break;
+ for (i = 0; i < n; i++)
+ if (s2[i] == s3[i])
+ dp[0][i + 1] = 1;
+ else
+ break;
+
+ for (i = 1; i <= m; ++i)
+ for (j = 1; j <= n; j++)
+ {
+ k = i + j;
+ if (s1[i - 1] == s3[k - 1])
+ dp[i][j] |= dp[i - 1][j];
+ if (s2[j - 1] == s3[k - 1])
+ dp[i][j] |= dp[i][j - 1];
+ }
+ return dp[m][n];
+ }
+};
```
### B
```cpp
-
+class Solution
+{
+public:
+ bool isInterleave(string s1, string s2, string s3)
+ {
+ if (s1.size() + s2.size() != s3.size())
+ return false;
+ int m = s1.size(), n = s2.size();
+ vector> dp(m + 1, vector(n + 1, false));
+ dp[0][0] = true;
+ for (int i = 1; i <= m; ++i)
+ dp[i][0] = dp[i - 1][0] && (s1[i - 1] == s3[i - 1]);
+ for (int i = 1; i <= n; ++i)
+ dp[0][i] = dp[0][i - 1] && (s2[i - 1] == s3[i - 1]);
+ for (int i = 1; i <= m; ++i)
+ for (int j = 1; j <= n; ++j)
+ {
+ dp[i][j] = (dp[i - 1][j] && s1[i - 1] == s3[i + j - 1]) || (dp[i][j - 1] && s2[j - 1] == s3[i + j - 1]);
+ }
+ return dp[m][n];
+ }
+};
```
### C
```cpp
-
+class Solution
+{
+public:
+ bool isInterleave(string s1, string s2, string s3)
+ {
+ int s1_len = s1.size();
+ int s2_len = s2.size();
+ int s3_len = s3.size();
+ if (s1_len + s2_len != s3_len)
+ return false;
+ if (s1_len == 0 || s2_len == 0)
+ return s1 + s2 == s3;
+ vector> dp(s1_len + 1, vector(s2_len + 1));
+ dp[0][0] = true;
+ for (int i = 0; i <= s1_len; i++)
+ {
+ for (int j = 0; j <= s2_len; j++)
+ {
+ if (dp[i][j])
+ {
+ if (i < s1_len && s1[i] == s3[i + j])
+ dp[i + 1][j] = true;
+ if (j < s2_len && s2[j] == s3[i + j])
+ dp[i][j + 1] = true;
+ }
+ }
+ }
+ return dp[s1_len][s2_len];
+ }
+};
```
diff --git "a/data_backup/1.leetcode/98_\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/solution.md" "b/data_backup/1.leetcode/98_\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/solution.md"
index 02f150cc85387262bf45ef586514a9d56e8d3aca..a6c4158b758a9622e727312bb9c5df7c43af088a 100644
--- "a/data_backup/1.leetcode/98_\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/solution.md"
+++ "b/data_backup/1.leetcode/98_\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/solution.md"
@@ -4,7 +4,18 @@
## aop
### before
```cpp
+#include
+using namespace std;
+struct TreeNode
+{
+ int val;
+ TreeNode *left;
+ TreeNode *right;
+ TreeNode() : val(0), left(nullptr), right(nullptr) {}
+ TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
+ TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
+};
```
### after
```cpp
@@ -13,21 +24,167 @@
## 答案
```cpp
-
+class Solution
+{
+public:
+ TreeNode *pre = NULL;
+ TreeNode *one = NULL;
+ TreeNode *two = NULL;
+ bool search(TreeNode *root)
+ {
+ if (root == NULL)
+ return false;
+ if (search(root->left))
+ return true;
+ if (pre != NULL && pre->val > root->val)
+ {
+ if (one == NULL)
+ {
+ one = root;
+ two = pre;
+ }
+ else
+ {
+ two = root;
+ return true;
+ }
+ }
+ pre = root;
+ if (search(root->right))
+ return true;
+ return false;
+ }
+ void recoverTree(TreeNode *root)
+ {
+ search(root);
+ swap(one->val, two->val);
+ }
+};
```
## 选项
### A
```cpp
-
+class Solution
+{
+public:
+ TreeNode *x, *y, *pre;
+ void DFS(TreeNode *root)
+ {
+ if (root == nullptr)
+ return;
+ DFS(root->left);
+ if (pre && root->val < pre->val)
+ {
+ x = root;
+ if (!y)
+ y = pre;
+ else
+ return;
+ }
+ pre = root;
+ DFS(root->right);
+ }
+ void recoverTree(TreeNode *root)
+ {
+ DFS(root);
+ swap(x->val, y->val);
+ }
+};
```
### B
```cpp
-
+class Solution
+{
+public:
+ void insert(int val, vector &vals)
+ {
+ if (vals.size() > 0)
+ {
+ for (int i = 0; i < vals.size(); i++)
+ {
+ if (val < vals[i])
+ {
+ vals.insert(vals.begin() + i, val);
+ return;
+ }
+ }
+ }
+ vals.push_back(val);
+ }
+ void recoverTree(TreeNode *root)
+ {
+ stack s;
+ vector vals;
+ TreeNode *tem = root;
+ while (tem || !s.empty())
+ {
+ while (tem)
+ {
+ s.push(tem);
+ tem = tem->left;
+ }
+ if (!s.empty())
+ {
+ tem = s.top();
+ s.pop();
+ insert(tem->val, vals);
+ tem = tem->right;
+ }
+ }
+ tem = root;
+ int j = 0;
+ while (tem || !s.empty())
+ {
+ while (tem)
+ {
+ s.push(tem);
+ tem = tem->left;
+ }
+ if (!s.empty())
+ {
+ tem = s.top();
+ s.pop();
+ tem->val = vals[j++];
+ tem = tem->right;
+ }
+ }
+ }
+};
```
### C
```cpp
-
+class Solution
+{
+public:
+ vector order;
+ void inOrder(TreeNode *root)
+ {
+ if (root->left)
+ inOrder(root->left);
+ order.push_back(root);
+ if (root->right)
+ inOrder(root->right);
+ }
+ void recoverTree(TreeNode *root)
+ {
+ inOrder(root);
+ int left = -1, right = -1;
+ for (int i = 0; i < order.size() - 1; ++i)
+ {
+ if (order[i]->val > order[i + 1]->val)
+ {
+ if (left == -1)
+ left = i;
+ right = i + 1;
+ }
+ }
+ if (right == -1)
+ swap(order[left]->val, order[left + 1]->val);
+ else
+ swap(order[left]->val, order[right]->val);
+ }
+};
```
diff --git "a/data_backup/1.leetcode/99_\347\233\270\345\220\214\347\232\204\346\240\221/solution.md" "b/data_backup/1.leetcode/99_\347\233\270\345\220\214\347\232\204\346\240\221/solution.md"
index 069816eb38c4cc91e5197e3acba70315234c5ab1..c58f0f3ecb4ff5179e5bf047974b64c14be21eb9 100644
--- "a/data_backup/1.leetcode/99_\347\233\270\345\220\214\347\232\204\346\240\221/solution.md"
+++ "b/data_backup/1.leetcode/99_\347\233\270\345\220\214\347\232\204\346\240\221/solution.md"
@@ -4,6 +4,18 @@
## aop
### before
```cpp
+#include
+using namespace std;
+
+struct TreeNode
+{
+ int val;
+ TreeNode *left;
+ TreeNode *right;
+ TreeNode() : val(0), left(nullptr), right(nullptr) {}
+ TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
+ TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
+};
```
### after
@@ -13,21 +25,66 @@
## 答案
```cpp
-
+都是错的
```
## 选项
### A
```cpp
-
+class Solution
+{
+public:
+ bool isSameTree(TreeNode *p, TreeNode *q)
+ {
+ if (p == nullptr)
+ return q == nullptr;
+ return q != nullptr && p->val == q->val && isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
+ }
+};
```
### B
```cpp
-
+class Solution
+{
+public:
+ bool isSameTree(TreeNode *p, TreeNode *q)
+ {
+ TreeNode *temp, *temq;
+ temp = p;
+ temq = q;
+ bool lb, rb;
+ if (!p && !q)
+ return true;
+ if ((!p || !q) || p->val != q->val)
+ return false;
+ else
+ {
+ lb = isSameTree(p->left, q->left);
+ rb = isSameTree(p->right, q->right);
+ }
+ if (lb && rb)
+ return true;
+ else
+ return false;
+ }
+};
```
### C
```cpp
-
+class Solution
+{
+public:
+ bool isSameTree(TreeNode *p, TreeNode *q)
+ {
+ if (p == NULL && q == NULL)
+ return true;
+ if (p == NULL || q == NULL)
+ return false;
+ if (p->val != q->val)
+ return false;
+ return (isSameTree(p->left, q->left) && isSameTree(p->right, q->right));
+ }
+};
```