提交 66b8b16b 编写于 作者: 每日一练社区's avatar 每日一练社区

add exercises

上级 4e68b806

要显示的变更太多。

To preserve performance only 1000 of 1000+ files are displayed.
{
"node_id": "algorithm-1457c70ac29a46a795c3a8aa8de0d34f",
"keywords": [
"leetcode",
"二叉树的锯齿形层序遍历"
],
"children": [],
"export": [
"solution.json"
],
"title": "二叉树的锯齿形层序遍历"
}
\ No newline at end of file
<p>给定一个二叉树,返回其节点值的锯齿形层序遍历。(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行)。</p>
<p>例如:<br />
给定二叉树 <code>[3,9,20,null,null,15,7]</code>,</p>
<pre>
3
/ \
9 20
/ \
15 7
</pre>
<p>返回锯齿形层序遍历如下:</p>
<pre>
[
[3],
[20,9],
[15,7]
]
</pre>
#include <vector>
#include <queue>
#include <cstddef>
using std::vector;
struct TreeNode
{
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
class Solution
{
public:
vector<vector<int>> zigzagLevelOrder(TreeNode *root)
{
vector<vector<int>> retv;
if (!root)
return retv;
std::queue<TreeNode *> q;
q.push(root);
bool reverse = false;
vector<int> v;
for (int cur_level_sz = 1, next_level_sz = 0; !q.empty();)
{
TreeNode *node = q.front();
q.pop();
v.push_back(node->val);
--cur_level_sz;
if (node->left)
{
q.push(node->left);
++next_level_sz;
}
if (node->right)
{
q.push(node->right);
++next_level_sz;
}
if (!cur_level_sz)
{
retv.push_back(reverse ? vector<int>(v.crbegin(), v.crend()) : v);
v.clear();
cur_level_sz = next_level_sz;
next_level_sz = 0;
reverse = !reverse;
}
}
return retv;
}
};
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d55fa143ea4b4a9b9cfc24a1e68e0e64"
}
\ No newline at end of file
# 二叉树的锯齿形层序遍历
<p>给定一个二叉树,返回其节点值的锯齿形层序遍历。(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行)。</p>
<p>例如:<br />
给定二叉树 <code>[3,9,20,null,null,15,7]</code>,</p>
<pre>
3
/ \
9 20
/ \
15 7
</pre>
<p>返回锯齿形层序遍历如下:</p>
<pre>
[
[3],
[20,9],
[15,7]
]
</pre>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
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:
vector<vector<int>> zigzagLevelOrder(TreeNode *root)
{
vector<vector<int>> result;
if (root == NULL)
{
return result;
}
deque<TreeNode *> node_queue;
node_queue.push_back(root);
node_queue.push_back(NULL);
deque<int> level_list;
bool is_order_left = true;
while (node_queue.size() > 0)
{
TreeNode *curr_node = node_queue.front();
node_queue.pop_front();
if (curr_node != NULL)
{
if (curr_node->left != NULL)
{
node_queue.push_back(curr_node->left);
}
if (curr_node->right != NULL)
{
node_queue.push_back(curr_node->right);
}
}
else
{
vector<int> tmp;
for (int a : level_list)
{
tmp.push_back(a);
}
result.push_back(tmp);
level_list.clear();
if (node_queue.size() > 0)
{
node_queue.push_back(NULL);
}
is_order_left = !is_order_left;
}
}
return result;
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
vector<vector<int>> zigzagLevelOrder(TreeNode *root)
{
if (root == NULL)
return {};
vector<vector<int>> res;
int flag = 1;
stack<TreeNode *> a, b;
a.push(root);
while (!a.empty() || !b.empty())
{
vector<int> cur;
while (flag == 1 && !a.empty())
{
root = a.top();
cur.push_back(root->val);
a.pop();
if (root->left != NULL)
b.push(root->left);
if (root->right != NULL)
b.push(root->right);
}
while (flag == -1 && !b.empty())
{
root = b.top();
cur.push_back(root->val);
b.pop();
if (root->right != NULL)
a.push(root->right);
if (root->left != NULL)
a.push(root->left);
}
flag = -1 * flag;
res.push_back(cur);
}
return res;
}
};
```
### B
```cpp
class Solution
{
public:
vector<vector<int>> zigzagLevelOrder(TreeNode *root)
{
vector<vector<int>> ans;
if (!root)
return ans;
queue<TreeNode *> qnode;
bool orderByLeft = true;
qnode.push(root);
while (!qnode.empty())
{
int levelSize = qnode.size();
deque<int> level;
for (int i = 0; i < levelSize; i++)
{
auto curNode = qnode.front();
qnode.pop();
if (orderByLeft)
{
level.push_back(curNode->val);
}
else
{
level.push_front(curNode->val);
}
if (curNode->left != NULL)
qnode.push(curNode->left);
if (curNode->right != NULL)
qnode.push(curNode->right);
}
orderByLeft = !orderByLeft;
vector<int> curlevel{level.begin(), level.end()};
ans.push_back(curlevel);
}
return ans;
}
};
```
### C
```cpp
class Solution
{
public:
vector<vector<int>> zigzagLevelOrder(TreeNode *root)
{
if (!root)
return {};
vector<vector<int>> res;
queue<TreeNode *> q{{root}};
int cnt = 0;
while (!q.empty())
{
vector<int> oneLevel;
for (int i = q.size(); i > 0; i--)
{
TreeNode *t = q.front();
q.pop();
oneLevel.push_back(t->val);
if (t->left)
q.push(t->left);
if (t->right)
q.push(t->right);
}
if (cnt % 2 == 1)
reverse(oneLevel.begin(), oneLevel.end());
res.push_back(oneLevel);
cnt++;
}
return res;
}
};
```
### D
```cpp
class Solution
{
public:
vector<vector<int>> zigzagLevelOrder(TreeNode *root)
{
vector<vector<int>> results;
if (root == NULL)
{
return results;
}
zigzagLevelOrderDFS_helper(root, 0, results);
return results;
}
void zigzagLevelOrderDFS_helper(TreeNode *node, int level, vector<vector<int>> &results)
{
if (level >= results.size())
{
vector<int> new_level;
new_level.push_back(node->val);
results.push_back(new_level);
}
else
{
if (level % 2 == 0)
{
results[level].push_back(node->val);
}
else
{
results[level].insert(results[level].begin(), node->val);
}
}
if (node->left != NULL)
{
zigzagLevelOrderDFS_helper(node->left, level + 1, results);
}
if (node->right != NULL)
{
zigzagLevelOrderDFS_helper(node->right, level + 1, results);
}
}
};
```
{
"node_id": "algorithm-587f3b68dc7047d5b2445cb0c5fc50c3",
"keywords": [
"leetcode",
"对称二叉树"
],
"children": [],
"export": [
"solution.json"
],
"title": "对称二叉树"
}
\ No newline at end of file
<p>给定一个二叉树,检查它是否是镜像对称的。</p>
<p>&nbsp;</p>
<p>例如,二叉树&nbsp;<code>[1,2,2,3,4,4,3]</code> 是对称的。</p>
<pre> 1
/ \
2 2
/ \ / \
3 4 4 3
</pre>
<p>&nbsp;</p>
<p>但是下面这个&nbsp;<code>[1,2,2,null,3,null,3]</code> 则不是镜像对称的:</p>
<pre> 1
/ \
2 2
\ \
3 3
</pre>
<p>&nbsp;</p>
<p><strong>进阶:</strong></p>
<p>你可以运用递归和迭代两种方法解决这个问题吗?</p>
#include <cstddef>
#include <stack>
struct TreeNode
{
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
class Solution
{
public:
bool isSymmetric(TreeNode *root)
{
if (root == NULL)
return true;
TreeNode *lt = root->left, *rt = root->right;
for (std::stack<TreeNode *> stack; !stack.empty() || (lt && rt);)
{
if (lt && rt)
{
if (lt->val != rt->val)
return false;
stack.push(lt->right);
stack.push(rt->left);
lt = lt->left;
rt = rt->right;
}
else if (lt || rt)
return false;
else
{
lt = stack.top();
stack.pop();
rt = stack.top();
stack.pop();
}
}
if (lt || rt)
return false;
else
return true;
}
};
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f1ce32e09e1e4a6baa582a6432191e67"
}
\ No newline at end of file
# 对称二叉树
<p>给定一个二叉树,检查它是否是镜像对称的。</p>
<p>&nbsp;</p>
<p>例如,二叉树&nbsp;<code>[1,2,2,3,4,4,3]</code> 是对称的。</p>
<pre> 1
/ \
2 2
/ \ / \
3 4 4 3
</pre>
<p>&nbsp;</p>
<p>但是下面这个&nbsp;<code>[1,2,2,null,3,null,3]</code> 则不是镜像对称的:</p>
<pre> 1
/ \
2 2
\ \
3 3
</pre>
<p>&nbsp;</p>
<p><strong>进阶:</strong></p>
<p>你可以运用递归和迭代两种方法解决这个问题吗?</p>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
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:
bool isSymmetric(TreeNode *root)
{
if (!root)
return true;
queue<TreeNode *> q;
q.push(root->left);
q.push(root->right);
while (!q.empty())
{
auto p1 = q.front();
q.pop();
auto p2 = q.front();
q.pop();
if (!p1 && !p2)
continue;
if (!p1 || !p2)
return false;
if (p1->val != p2->val)
return false;
q.push(p1->right);
q.push(p1->left);
q.push(p2->right);
q.push(p2->left);
}
return true;
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
bool isSymmetric(TreeNode *root)
{
queue<TreeNode *> q1, q2;
if (!root)
return true;
q1.push(root->left);
q2.push(root->right);
while (!q1.empty() && !q2.empty())
{
TreeNode *node1 = q1.front();
q1.pop();
TreeNode *node2 = q2.front();
q2.pop();
if (!node1 && !node2)
continue;
if ((!node1 && node2) || (node1 && !node2) || (node1->val != node2->val))
return false;
q1.push(node1->left);
q1.push(node1->right);
q2.push(node2->right);
q2.push(node2->left);
}
return true;
}
};
```
### B
```cpp
class Solution
{
public:
bool isSymmetric(TreeNode *root)
{
if (!root)
return true;
return helper(root->left, root->right);
}
bool helper(TreeNode *left, TreeNode *right)
{
if (!left && !right)
return true;
if ((!left && right) || (left && !right) || (left->val != right->val))
return false;
return helper(left->left, right->right) && helper(left->right, right->left);
}
};
```
### C
```cpp
class Solution
{
public:
bool isSymmetric(TreeNode *root)
{
return ismirror(root, root);
}
bool ismirror(TreeNode *t1, TreeNode *t2)
{
if (t1 == NULL && t2 == NULL)
return true;
if (t1 == NULL || t2 == NULL)
return false;
return (t1->val == t2->val) && ismirror(t1->left, t2->right) && ismirror(t1->right, t2->left);
}
};
```
{
"node_id": "algorithm-894e8b4e12a64b228b73d75b3fe22817",
"keywords": [
"leetcode",
"二叉树的层序遍历"
],
"children": [],
"export": [
"solution.json"
],
"title": "二叉树的层序遍历"
}
\ No newline at end of file
<p>给你一个二叉树,请你返回其按 <strong>层序遍历</strong> 得到的节点值。 (即逐层地,从左到右访问所有节点)。</p>
<p> </p>
<p><strong>示例:</strong><br />
二叉树:<code>[3,9,20,null,null,15,7]</code>,</p>
<pre>
3
/ \
9 20
/ \
15 7
</pre>
<p>返回其层序遍历结果:</p>
<pre>
[
[3],
[9,20],
[15,7]
]
</pre>
#include <vector>
#include <deque>
#include <cstddef>
using std::deque;
using std::vector;
struct TreeNode
{
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
class Solution
{
public:
vector<vector<int>> levelOrder(TreeNode *root)
{
vector<vector<int>> retv;
if (root)
{
deque<TreeNode *> q{root};
while (!q.empty())
{
vector<int> v;
for (decltype(q.size()) i = 0, n = q.size(); i != n; ++i)
{
TreeNode *node = q.front();
q.pop_front();
v.push_back(node->val);
if (node->left)
q.push_back(node->left);
if (node->right)
q.push_back(node->right);
}
retv.push_back(v);
}
}
return retv;
}
};
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9290e1345143424f8a116ab56f88f50e"
}
\ No newline at end of file
# 二叉树的层序遍历
<p>给你一个二叉树,请你返回其按 <strong>层序遍历</strong> 得到的节点值。 (即逐层地,从左到右访问所有节点)。</p>
<p> </p>
<p><strong>示例:</strong><br />
二叉树:<code>[3,9,20,null,null,15,7]</code>,</p>
<pre>
3
/ \
9 20
/ \
15 7
</pre>
<p>返回其层序遍历结果:</p>
<pre>
[
[3],
[9,20],
[15,7]
]
</pre>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
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:
vector<vector<int>> levelOrder(TreeNode *root)
{
vector<vector<int>> res;
queue<TreeNode *> q;
if (root != NULL)
{
while (!q.empty())
{
int size = q.size();
vector<int> temp;
for (int i = 0; i < size; i++)
{
TreeNode *t = q.front();
q.pop();
temp.push_back(t->val);
if (t->left != NULL)
q.push(t->left);
if (t->right != NULL)
q.push(t->right);
}
res.push_back(temp);
temp.clear();
}
}
return res;
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
vector<vector<int>> levelOrder(TreeNode *root)
{
vector<vector<int>> ret;
if (!root)
return ret;
queue<TreeNode *> q;
q.push(root);
while (!q.empty())
{
int currNodeSize = q.size();
ret.push_back(vector<int>());
for (int i = 1; i <= currNodeSize; i++)
{
TreeNode *node = q.front();
q.pop();
ret.back().push_back(node->val);
if (node->left)
q.push(node->left);
if (node->right)
q.push(node->right);
}
}
return ret;
}
};
```
### B
```cpp
class Solution
{
public:
int depth(TreeNode *root)
{
if (root == NULL)
return 0;
return max(depth(root->left), depth(root->right)) + 1;
}
void levelOrder(vector<vector<int>> &ans, TreeNode *node, int level)
{
if (!node)
return;
ans[level].push_back(node->val);
levelOrder(ans, node->left, level - 1);
levelOrder(ans, node->right, level - 1);
}
vector<vector<int>> levelOrderBottom(TreeNode *root)
{
int d = depth(root);
vector<vector<int>> ans(d, vector<int>{});
levelOrder(ans, root, d - 1);
return ans;
}
};
```
### C
```cpp
class Solution
{
public:
void dfs(TreeNode *root, vector<vector<int>> &res)
{
queue<TreeNode *> q;
q.push(root);
while (!q.empty())
{
int sz = q.size();
vector<int> tp;
while (sz > 0)
{
TreeNode *p = q.front();
q.pop();
if (p->left != NULL)
{
q.push(p->left);
}
if (p->right != NULL)
{
q.push(p->right);
}
tp.push_back(p->val);
sz--;
}
res.push_back(tp);
}
}
vector<vector<int>> levelOrder(TreeNode *root)
{
vector<vector<int>> res;
if (root == NULL)
{
return res;
}
dfs(root, res);
return res;
}
};
```
{
"node_id": "algorithm-602c74771c664b6798149723fa790697",
"keywords": [
"leetcode",
"分数到小数"
],
"children": [],
"export": [
"solution.json"
],
"title": "分数到小数"
}
\ No newline at end of file
<p>给定两个整数,分别表示分数的分子 <code>numerator</code> 和分母 <code>denominator</code>,以 <strong>字符串形式返回小数</strong></p>
<p>如果小数部分为循环小数,则将循环的部分括在括号内。</p>
<p class="MachineTrans-lang-zh-CN">如果存在多个答案,只需返回 <strong>任意一个</strong></p>
<p class="MachineTrans-lang-zh-CN">对于所有给定的输入,<strong>保证</strong> 答案字符串的长度小于 <code>10<sup>4</sup></code></p>
<p> </p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong>numerator = 1, denominator = 2
<strong>输出:</strong>"0.5"
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong>numerator = 2, denominator = 1
<strong>输出:</strong>"2"
</pre>
<p><strong>示例 3:</strong></p>
<pre>
<strong>输入:</strong>numerator = 2, denominator = 3
<strong>输出:</strong>"0.(6)"
</pre>
<p><strong>示例 4:</strong></p>
<pre>
<strong>输入:</strong>numerator = 4, denominator = 333
<strong>输出:</strong>"0.(012)"
</pre>
<p><strong>示例 5:</strong></p>
<pre>
<strong>输入:</strong>numerator = 1, denominator = 5
<strong>输出:</strong>"0.2"
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>-2<sup>31</sup> <numerator, denominator <= 2<sup>31</sup> - 1</code></li>
<li><code>denominator != 0</code></li>
</ul>
class Solution
{
public:
string fractionToDecimal(int numerator, int denominator)
{
int m1 = numerator > 0 ? 1 : -1;
int m2 = denominator > 0 ? 1 : -1;
long long num = abs((long long)numerator);
long long den = abs((long long)denominator);
long long t = num / den;
long long res = num % den;
string ans = to_string(t);
if (m1 * m2 == -1 && (t > 0 || res > 0))
ans = '-' + ans;
if (res == 0)
return ans;
ans += '.';
unordered_map<long long, int> m;
string s = "";
int pos = 0;
while (res != 0)
{
if (m.find(res) != m.end())
{
s.insert(m[res], "(");
s += ')';
return ans + s;
}
m[res] = pos;
s += to_string((res * 10) / den);
res = (res * 10) % den;
pos++;
}
return ans + s;
}
};
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1a7236d672a24076bcc0f1eff7050847"
}
\ No newline at end of file
# 分数到小数
<p>给定两个整数,分别表示分数的分子 <code>numerator</code> 和分母 <code>denominator</code>,以 <strong>字符串形式返回小数</strong></p>
<p>如果小数部分为循环小数,则将循环的部分括在括号内。</p>
<p class="MachineTrans-lang-zh-CN">如果存在多个答案,只需返回 <strong>任意一个</strong></p>
<p class="MachineTrans-lang-zh-CN">对于所有给定的输入,<strong>保证</strong> 答案字符串的长度小于 <code>10<sup>4</sup></code></p>
<p> </p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong>numerator = 1, denominator = 2
<strong>输出:</strong>"0.5"
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong>numerator = 2, denominator = 1
<strong>输出:</strong>"2"
</pre>
<p><strong>示例 3:</strong></p>
<pre>
<strong>输入:</strong>numerator = 2, denominator = 3
<strong>输出:</strong>"0.(6)"
</pre>
<p><strong>示例 4:</strong></p>
<pre>
<strong>输入:</strong>numerator = 4, denominator = 333
<strong>输出:</strong>"0.(012)"
</pre>
<p><strong>示例 5:</strong></p>
<pre>
<strong>输入:</strong>numerator = 1, denominator = 5
<strong>输出:</strong>"0.2"
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>-2<sup>31</sup> <numerator, denominator <= 2<sup>31</sup> - 1</code></li>
<li><code>denominator != 0</code></li>
</ul>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
Solution sol;
string res;
int numerator = 1, denominator = 2;
res = sol.fractionToDecimal(numerator, denominator);
cout << res;
return 0;
}
```
## 答案
```cpp
class Solution
{
public:
const static int CACHE_SIZE = 1000;
string fractionToDecimal(int numerator, int denominator)
{
if (numerator == 0)
return "0";
bool isNegative = numerator < 0 ^ denominator < 0;
double doubleNumerator = fabs(numerator);
double doubleDenominator = fabs(denominator);
double integral = floor(doubleNumerator / doubleDenominator);
doubleNumerator -= doubleDenominator * integral;
int len = 0;
string cache;
vector<double> dividendCache;
bool isRecurring = false;
int recurringStart = 0;
int i = 0;
while (doubleNumerator)
{
doubleNumerator *= 10;
len = dividendCache.size();
for (i = 0; i < len; ++i)
if (dividendCache[i] == doubleNumerator)
{
isRecurring = true;
recurringStart = i;
break;
}
if (isRecurring)
break;
i = (int)(floor(doubleNumerator / doubleDenominator));
cache += i;
dividendCache.push_back(doubleNumerator);
doubleNumerator -= doubleDenominator * i;
}
string ret = isNegative ? "-" : "";
string tmp;
char c;
if (integral == 0)
ret += "0";
else
{
while (integral)
{
c = (int)(integral - 10 * floor(integral / 10)) + '0';
tmp = c + tmp;
integral = floor(integral / 10);
}
ret += tmp;
}
if (dividendCache.size() > 0)
ret += '.';
i = 0;
if (isRecurring)
{
ret += cache.substr(0, recurringStart);
ret += '(';
ret += cache.substr(recurringStart);
ret += ')';
}
else
ret += cache;
return ret;
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
string fractionToDecimal(int numerator, int denominator)
{
typedef long long LL;
LL x = numerator, y = denominator;
if (x % y == 0)
return to_string(x / y);
string res;
if ((x < 0) ^ (y < 0))
res += '-';
x = abs(x), y = abs(y);
res += to_string(x / y) + '.';
x %= y;
unordered_map<LL, int> hash;
while (x)
{
hash[x] = res.size();
x *= 10;
res += to_string(x / y);
x %= y;
if (hash.count(x))
{
res = res.substr(0, hash[x]) + '(' + res.substr(hash[x]) + ')';
break;
}
}
return res;
}
};
```
### B
```cpp
class Solution
{
public:
string fractionToDecimal(int numerator, int denominator)
{
string ans;
unordered_map<long, int> use;
if (numerator > 0 && denominator < 0 || numerator < 0 && denominator > 0)
ans = '-';
long numerat = fabs(numerator);
long denominat = fabs(denominator);
ans += to_string(numerat / denominat);
numerat = numerat % denominat;
int point, x;
if (numerat)
{
ans += ".";
point = ans.length() - 1;
}
else
return ans;
while (numerat && use.count(numerat) == 0)
{
use[numerat] = ++point;
numerat *= 10;
x = numerat / denominat;
numerat = numerat % denominat;
ans.push_back(x + '0');
}
if (numerat)
{
ans.insert(ans.begin() + use[numerat], '(');
ans.push_back(')');
}
return ans;
}
};
```
### C
```cpp
class Solution
{
public:
string fractionToDecimal(int numerator, int denominator)
{
int m1 = numerator > 0 ? 1 : -1;
int m2 = denominator > 0 ? 1 : -1;
long long num = abs((long long)numerator);
long long den = abs((long long)denominator);
long long t = num / den;
long long res = num % den;
string ans = to_string(t);
if (m1 * m2 == -1 && (t > 0 || res > 0))
ans = '-' + ans;
if (res == 0)
return ans;
ans += '.';
unordered_map<long long, int> m;
string s = "";
int pos = 0;
while (res != 0)
{
if (m.find(res) != m.end())
{
s.insert(m[res], "(");
s += ')';
return ans + s;
}
m[res] = pos;
s += to_string((res * 10) / den);
res = (res * 10) % den;
pos++;
}
return ans + s;
}
};
```
{
"node_id": "algorithm-4458b593b07f4ee1b06db455c9f09209",
"keywords": [
"leetcode",
"单词接龙 II"
],
"children": [],
"export": [
"solution.json"
],
"title": "单词接龙 II"
}
\ No newline at end of file
<p>按字典 <code>wordList</code> 完成从单词 <code>beginWord</code> 到单词 <code>endWord</code> 转化,一个表示此过程的 <strong>转换序列</strong> 是形式上像 <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> 这样的单词序列,并满足:</p>
<div class="original__bRMd">
<div>
<ul>
<li>每对相邻的单词之间仅有单个字母不同。</li>
<li>转换过程中的每个单词 <code>s<sub>i</sub></code><code>1 <= i <= k</code>)必须是字典 <code>wordList</code> 中的单词。注意,<code>beginWord</code> 不必是字典 <code>wordList</code> 中的单词。</li>
<li><code>s<sub>k</sub> == endWord</code></li>
</ul>
<p>给你两个单词 <code>beginWord</code><code>endWord</code> ,以及一个字典 <code>wordList</code> 。请你找出并返回所有从 <code>beginWord</code><code>endWord</code><strong>最短转换序列</strong> ,如果不存在这样的转换序列,返回一个空列表。每个序列都应该以单词列表<em> </em><code>[beginWord, s<sub>1</sub>, s<sub>2</sub>, ..., s<sub>k</sub>]</code> 的形式返回。</p>
<p> </p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong>beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"]
<strong>输出:</strong>[["hit","hot","dot","dog","cog"],["hit","hot","lot","log","cog"]]
<strong>解释:</strong>存在 2 种最短的转换序列:
"hit" -> "hot" -> "dot" -> "dog" -> "cog"
"hit" -> "hot" -> "lot" -> "log" -> "cog"
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong>beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log"]
<strong>输出:</strong>[]
<strong>解释:</strong>endWord "cog" 不在字典 wordList 中,所以不存在符合要求的转换序列。
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= beginWord.length <= 7</code></li>
<li><code>endWord.length == beginWord.length</code></li>
<li><code>1 <= wordList.length <= 5000</code></li>
<li><code>wordList[i].length == beginWord.length</code></li>
<li><code>beginWord</code><code>endWord</code><code>wordList[i]</code> 由小写英文字母组成</li>
<li><code>beginWord != endWord</code></li>
<li><code>wordList</code> 中的所有单词 <strong>互不相同</strong></li>
</ul>
</div>
</div>
class Solution
{
public:
unordered_map<string, vector<string>> tree; // 构建图
vector<vector<string>> ans; // 存放最终结果
void dfs(vector<string> &cur, string curWord, string endWord)
{
if (curWord == endWord)
{
ans.push_back(cur);
return;
}
for (string s : tree[curWord])
{
cur.push_back(s);
dfs(cur, s, endWord);
cur.pop_back();
}
}
vector<vector<string>> findLadders(string beginWord, string endWord, vector<string> &wordList)
{
if (wordList.size() == 0 || find(wordList.begin(), wordList.end(), endWord) == wordList.end())
return {};
unordered_set<string> bfsFromBegin{beginWord}; // 自顶向下的BFS队列 !!!注意使用集合
unordered_set<string> bfsFromEnd{endWord}; // 自底向上的BFS队列 !!!注意使用集合
unordered_set<string> dirc(wordList.begin(), wordList.end()); // 初始化字典 记录未被访问过的字符串 !!!注意初始化方式
bool findFlag = false, reverseFlag = false; // findFlag两队列是否存在相同的元素 reverseflag时刻标记当前BFS遍历的方向(false为自顶向下,true为自底向上)
while (!bfsFromBegin.empty())
{
unordered_set<string> next; // 存放下一层需要遍历的节点(由于此处BFS的特殊性【一次性扩展所有节点】,所以不是直接添加到原先队列的末尾,而是借助next)
for (string s : bfsFromBegin) // 遍历过的节点从set中删除 避免成环
dirc.erase(s);
for (string s1 : bfsFromBegin)
{ // 扩展下一层的节点
for (int i = 0; i < s1.size(); ++i)
{
string s2 = s1; // s2记录由s1扩展而来字符串 !!!注意这条语句不要放错位置
for (char c = 'a'; c <= 'z'; ++c)
{
s2[i] = c;
if (dirc.count(s2) == 0)
continue;
if (bfsFromEnd.count(s2))
{
findFlag = true; // 找到双向BFS重合的字符串,BFS过程即可终止
}
else
{
next.insert(s2); // 将字符串加入扩展队列
}
reverseFlag ? tree[s2].push_back(s1) : tree[s1].push_back(s2); // 构建树 并始终保持方向从beginWord指向endWord
}
}
}
bfsFromBegin = next; // 更新队列
if (bfsFromBegin.size() > bfsFromEnd.size())
{
reverseFlag = !reverseFlag; // 取反
swap(bfsFromBegin, bfsFromEnd); // 交换BFS的队列 改变BFS的方向
}
if (findFlag)
break; // 双向BFS交汇 BFS过程终止
}
vector<string> cur = {beginWord};
dfs(cur, beginWord, endWord); // 遍历形成的树 得到起点到终点的路径
return ans;
}
};
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "84292d0d29094d59bd5be678c4c853e4"
}
\ No newline at end of file
# 单词接龙 II
<p>按字典 <code>wordList</code> 完成从单词 <code>beginWord</code> 到单词 <code>endWord</code> 转化,一个表示此过程的 <strong>转换序列</strong> 是形式上像 <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> 这样的单词序列,并满足:</p>
<div class="original__bRMd">
<div>
<ul>
<li>每对相邻的单词之间仅有单个字母不同。</li>
<li>转换过程中的每个单词 <code>s<sub>i</sub></code><code>1 <= i <= k</code>)必须是字典 <code>wordList</code> 中的单词。注意,<code>beginWord</code> 不必是字典 <code>wordList</code> 中的单词。</li>
<li><code>s<sub>k</sub> == endWord</code></li>
</ul>
<p>给你两个单词 <code>beginWord</code><code>endWord</code> ,以及一个字典 <code>wordList</code> 。请你找出并返回所有从 <code>beginWord</code><code>endWord</code><strong>最短转换序列</strong> ,如果不存在这样的转换序列,返回一个空列表。每个序列都应该以单词列表<em> </em><code>[beginWord, s<sub>1</sub>, s<sub>2</sub>, ..., s<sub>k</sub>]</code> 的形式返回。</p>
<p> </p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong>beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"]
<strong>输出:</strong>[["hit","hot","dot","dog","cog"],["hit","hot","lot","log","cog"]]
<strong>解释:</strong>存在 2 种最短的转换序列:
"hit" -> "hot" -> "dot" -> "dog" -> "cog"
"hit" -> "hot" -> "lot" -> "log" -> "cog"
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong>beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log"]
<strong>输出:</strong>[]
<strong>解释:</strong>endWord "cog" 不在字典 wordList 中,所以不存在符合要求的转换序列。
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= beginWord.length <= 7</code></li>
<li><code>endWord.length == beginWord.length</code></li>
<li><code>1 <= wordList.length <= 5000</code></li>
<li><code>wordList[i].length == beginWord.length</code></li>
<li><code>beginWord</code><code>endWord</code><code>wordList[i]</code> 由小写英文字母组成</li>
<li><code>beginWord != endWord</code></li>
<li><code>wordList</code> 中的所有单词 <strong>互不相同</strong></li>
</ul>
</div>
</div>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
Solution sol;
vector<vector<string>> res;
string beginWord = "hit", endWord = "cog";
vector<string> wordList = {"hot", "dot", "dog", "lot", "log", "cog"};
res = sol.findLadders(beginWord, endWord, wordList);
for (auto i : res)
{
for (auto j : i)
cout << j << " ";
cout << endl;
}
return 0;
}
```
## 答案
```cpp
class Solution
{
public:
unordered_map<string, vector<string>> tree;
vector<vector<string>> ans;
void dfs(vector<string> &cur, string curWord, string endWord)
{
if (curWord == endWord)
{
ans.push_back(cur);
return;
}
for (string s : tree[curWord])
{
cur.push_back(s);
dfs(cur, s, endWord);
cur.pop_back();
}
}
vector<vector<string>> findLadders(string beginWord, string endWord, vector<string> &wordList)
{
if (wordList.size() == 0 || find(wordList.begin(), wordList.end(), endWord) == wordList.end())
return {};
unordered_set<string> bfsFromBegin{beginWord};
unordered_set<string> bfsFromEnd{endWord};
unordered_set<string> dirc(wordList.begin(), wordList.end());
bool findFlag = false, reverseFlag = false;
while (!bfsFromBegin.empty())
{
unordered_set<string> next;
for (string s : bfsFromBegin)
dirc.erase(s);
for (string s1 : bfsFromBegin)
{
for (int i = 0; i < s1.size(); ++i)
{
string s2 = s1;
for (char c = 'a'; c <= 'z'; ++c)
{
s2[i] = c;
if (dirc.count(s2) == 0)
continue;
next.insert(s2);
}
reverseFlag ? tree[s2].push_back(s1) : tree[s1].push_back(s2);
}
}
bfsFromBegin = next;
if (bfsFromBegin.size() > bfsFromEnd.size())
{
reverseFlag = !reverseFlag;
swap(bfsFromBegin, bfsFromEnd);
}
if (findFlag)
break;
}
vector<string> cur = {beginWord};
dfs(cur, beginWord, endWord);
return ans;
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
bool differ_one(string &s, string &t)
{
int n = 0;
for (int i = 0; i < s.size(); ++i)
if ((n += s[i] != t[i]) > 1)
return false;
return n == 1;
}
vector<vector<int>> fa;
vector<string> tmp;
vector<vector<string>> ans;
void dfs(int index, vector<string> &wordList)
{
if (fa[index].empty())
{
reverse(tmp.begin(), tmp.end());
ans.push_back(tmp);
reverse(tmp.begin(), tmp.end());
}
for (auto &x : fa[index])
{
tmp.push_back(wordList[x]);
dfs(x, wordList);
tmp.pop_back();
}
}
vector<vector<string>> findLadders(string beginWord, string endWord, vector<string> &wordList)
{
int b = -1, e = -1, x;
for (int i = 0; i < wordList.size(); ++i)
{
if (wordList[i] == beginWord)
b = i;
if (wordList[i] == endWord)
e = i;
}
if (e == -1)
return ans;
if (b == -1)
wordList.push_back(beginWord), b = wordList.size() - 1;
queue<int> que;
fa.assign(wordList.size(), vector<int>());
vector<int> index(wordList.size(), 0);
que.push(b), index[b] = 1;
while (!que.empty())
{
x = que.front(), que.pop();
if (index[e] && index[x] >= index[e])
break;
for (int i = 0; i < wordList.size(); ++i)
if ((index[i] == 0 || index[x] + 1 == index[i]) && differ_one(wordList[x], wordList[i]))
if (index[i] == 0)
index[i] = index[x] + 1, que.push(i), fa[i].push_back(x);
else
fa[i].push_back(x);
}
if (index[e] == 0)
return ans;
tmp.push_back(endWord);
dfs(e, wordList);
tmp.pop_back();
return ans;
}
};
```
### B
```cpp
class Solution
{
public:
vector<vector<string>> findLadders(string beginWord, string endWord, vector<string> &wordList)
{
unordered_set<string> list(wordList.begin(), wordList.end());
if (!list.count(endWord))
return {};
unordered_map<string, unordered_set<string>> trace;
unordered_set<string> p;
unordered_set<string> q{beginWord};
while (q.size() && !trace.count(endWord))
{
for (auto w : q)
{
list.erase(w);
}
p.clear();
for (auto str : q)
{
for (int i = 0; i < str.size(); ++i)
{
string tmp = str;
for (char c = 'a'; c <= 'z'; ++c)
{
tmp[i] = c;
if (list.find(tmp) == list.end())
continue;
trace[tmp].insert(str);
p.insert(tmp);
}
}
}
q = p;
}
if (!trace.size())
return {};
vector<vector<string>> res;
dfs(res, {}, trace, endWord);
return res;
}
void dfs(vector<vector<string>> &res, vector<string> path, unordered_map<string, unordered_set<string>> &trace, string &str)
{
path.push_back(str);
if (trace.count(str) == 0)
{
reverse(path.begin(), path.end());
res.push_back(path);
return;
}
for (auto word : trace[str])
dfs(res, path, trace, word);
}
};
```
### C
```cpp
class Solution
{
public:
vector<vector<string>> findLadders(string beginWord, string endWord, vector<string> &wordList)
{
vector<vector<string>> ans;
unordered_set<string> dict(wordList.begin(), wordList.end());
vector<string> p{beginWord};
queue<vector<string>> paths;
paths.push(p);
unordered_set<string> words;
int level = 1, minlength = INT_MAX;
while (!paths.empty())
{
vector<string> t = paths.front();
paths.pop();
if (t.size() > level)
{
for (string s : words)
dict.erase(s);
words.clear();
level = t.size();
if (level > minlength)
break;
}
string last = t.back();
for (int i = 0; i < last.size(); ++i)
{
string newlast = last;
for (char ch = 'a'; ch <= 'z'; ++ch)
{
newlast[i] = ch;
if (!dict.count(newlast))
continue;
words.insert(newlast);
vector<string> nextpath = t;
nextpath.push_back(newlast);
if (newlast == endWord)
{
ans.push_back(nextpath);
minlength = level;
}
else
{
paths.push(nextpath);
}
}
}
}
return ans;
}
};
```
{
"node_id": "algorithm-6df957f509fc40d1ae8a9736bd2401dc",
"keywords": [
"leetcode",
"单词接龙"
],
"children": [],
"export": [
"solution.json"
],
"title": "单词接龙"
}
\ No newline at end of file
<p>字典 <code>wordList</code> 中从单词 <code>beginWord</code><em> </em><code>endWord</code><strong>转换序列 </strong>是一个按下述规格形成的序列:</p>
<ul>
<li>序列中第一个单词是 <code>beginWord</code></li>
<li>序列中最后一个单词是 <code>endWord</code></li>
<li>每次转换只能改变一个字母。</li>
<li>转换过程中的中间单词必须是字典 <code>wordList</code> 中的单词。</li>
</ul>
<p>给你两个单词<em> </em><code>beginWord</code><em> </em><code>endWord</code> 和一个字典 <code>wordList</code> ,找到从 <code>beginWord</code> 到 <code>endWord</code><strong>最短转换序列</strong> 中的 <strong>单词数目</strong> 。如果不存在这样的转换序列,返回 0。</p>
 
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong>beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"]
<strong>输出:</strong>5
<strong>解释:</strong>一个最短转换序列是 "hit" -> "hot" -> "dot" -> "dog" -> "cog", 返回它的长度 5。
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong>beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log"]
<strong>输出:</strong>0
<strong>解释:</strong>endWord "cog" 不在字典中,所以无法进行转换。</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= beginWord.length <= 10</code></li>
<li><code>endWord.length == beginWord.length</code></li>
<li><code>1 <= wordList.length <= 5000</code></li>
<li><code>wordList[i].length == beginWord.length</code></li>
<li><code>beginWord</code><code>endWord</code><code>wordList[i]</code> 由小写英文字母组成</li>
<li><code>beginWord != endWord</code></li>
<li><code>wordList</code> 中的所有字符串 <strong>互不相同</strong></li>
</ul>
//Dijkstra算法的思路
class Solution
{
public:
int ladderLength(string beginWord, string endWord, vector<string> &wordList)
{
unordered_set<string> set(wordList.begin(), wordList.end());
if (!set.count(endWord))
return 0;
queue<pair<string, int>> q; //<字符串,该字符串到beginword的距离>
q.push({beginWord, 1});
while (!q.empty())
{
string cur = q.front().first;
int step = q.front().second;
q.pop();
if (cur == endWord)
return step;
for (int i = 0; i < cur.size(); ++i)
{
char ch = cur[i];
//遍历字母来寻找距离为1(只用改变一个字母)的单词,也即可达的单词
for (char c = 'a'; c <= 'z'; ++c)
{
if (c == ch)
continue;
cur[i] = c; //替换单个字符
if (set.count(cur))
{
q.push({cur, 1 + step});
set.erase(cur); //该节点使用过了,需要进行删除
}
}
cur[i] = ch; //复原
}
}
return 0;
}
};
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3cee91c0e09040b7b0c46b7f5ebb7cc5"
}
\ No newline at end of file
# 单词接龙
<p>字典 <code>wordList</code> 中从单词 <code>beginWord</code><em> </em><code>endWord</code><strong>转换序列 </strong>是一个按下述规格形成的序列:</p>
<ul>
<li>序列中第一个单词是 <code>beginWord</code></li>
<li>序列中最后一个单词是 <code>endWord</code></li>
<li>每次转换只能改变一个字母。</li>
<li>转换过程中的中间单词必须是字典 <code>wordList</code> 中的单词。</li>
</ul>
<p>给你两个单词<em> </em><code>beginWord</code><em> </em><code>endWord</code> 和一个字典 <code>wordList</code> ,找到从 <code>beginWord</code> 到 <code>endWord</code><strong>最短转换序列</strong> 中的 <strong>单词数目</strong> 。如果不存在这样的转换序列,返回 0。</p>
 
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong>beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"]
<strong>输出:</strong>5
<strong>解释:</strong>一个最短转换序列是 "hit" -> "hot" -> "dot" -> "dog" -> "cog", 返回它的长度 5。
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong>beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log"]
<strong>输出:</strong>0
<strong>解释:</strong>endWord "cog" 不在字典中,所以无法进行转换。</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= beginWord.length <= 10</code></li>
<li><code>endWord.length == beginWord.length</code></li>
<li><code>1 <= wordList.length <= 5000</code></li>
<li><code>wordList[i].length == beginWord.length</code></li>
<li><code>beginWord</code><code>endWord</code><code>wordList[i]</code> 由小写英文字母组成</li>
<li><code>beginWord != endWord</code></li>
<li><code>wordList</code> 中的所有字符串 <strong>互不相同</strong></li>
</ul>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
Solution sol;
int res;
string beginWord = "hit", endWord = "cog";
vector<string> wordList = {"hot", "dot", "dog", "lot", "log", "cog"};
res = sol.ladderLength(beginWord, endWord, wordList);
cout << res;
return 0;
}
```
## 答案
```cpp
class Solution
{
public:
int ladderLength(string beginWord, string endWord, vector<string> &wordList)
{
unordered_set<string> word;
for (auto s : wordList)
{
word.insert(s);
}
if (word.find(endWord) == word.end())
{
return 0;
}
queue<string> que;
que.push(beginWord);
unordered_set<string> visited;
visited.insert(beginWord);
int num = 1;
while (!que.empty())
{
int m = que.size();
for (int i = 0; i < m; i++)
{
string str = que.front();
que.pop();
if (str == endWord)
{
return num;
}
for (int j = 0; j < str.size(); j++)
{
string ss = str;
for (int k = 0; k < 26; k++)
{
char c = k + 'a';
if (c != str[j])
{
ss[j] = c;
}
if (visited.find(ss) == visited.end())
{
visited.insert(ss);
que.push(ss);
}
}
}
}
num++;
}
return 0;
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
int ladderLength(string beginWord, string endWord, vector<string> &wordList)
{
unordered_set<string> wordSet(wordList.begin(), wordList.end());
if (!wordSet.count(endWord))
return 0;
unordered_map<string, int> pathCount{{{beginWord, 1}}};
queue<string> q{{beginWord}};
while (!q.empty())
{
string word = q.front();
q.pop();
for (int i = 0; i < word.size(); i++)
{
string newWord = word;
for (char c = 'a'; c <= 'z'; c++)
{
newWord[i] = c;
if (wordSet.count(newWord) && newWord == endWord)
return pathCount[word] + 1;
if (wordSet.count(newWord) && !pathCount.count(newWord))
{
pathCount[newWord] = pathCount[word] + 1;
q.push(newWord);
}
}
}
}
return 0;
}
};
```
### B
```cpp
class Solution
{
public:
int ladderLength(string beginWord, string endWord, vector<string> &wordList)
{
queue<string> q;
map<string, int> m1;
map<string, int> re;
int n = wordList.size();
for (int i = 0; i < n; i++)
m1[wordList[i]] = 1;
re[beginWord] = 1;
q.push(beginWord);
while ((!q.empty()) && m1.size())
{
string now = q.front();
q.pop();
int num = re[now];
int llen = now.size();
for (int i = 0; i < llen; i++)
{
string temp = now;
for (char c = 'a'; c <= 'z'; c++)
{
if (temp[i] == c)
continue;
else
temp[i] = c;
if (m1.find(temp) != m1.end())
{
if (temp == endWord)
return num + 1;
q.push(temp);
re[temp] = num + 1;
m1.erase(temp);
}
}
}
}
return 0;
}
};
```
### C
```cpp
class Solution
{
public:
int ladderLength(string beginWord, string endWord, vector<string> &wordList)
{
unordered_set<string> set(wordList.begin(), wordList.end());
if (!set.count(endWord))
return 0;
queue<pair<string, int>> q;
q.push({beginWord, 1});
while (!q.empty())
{
string cur = q.front().first;
int step = q.front().second;
q.pop();
if (cur == endWord)
return step;
for (int i = 0; i < cur.size(); ++i)
{
char ch = cur[i];
for (char c = 'a'; c <= 'z'; ++c)
{
if (c == ch)
continue;
cur[i] = c;
if (set.count(cur))
{
q.push({cur, 1 + step});
set.erase(cur);
}
}
cur[i] = ch;
}
}
return 0;
}
};
```
{
"node_id": "algorithm-78586cd84fd946a3ab3df877877a7a70",
"keywords": [
"leetcode",
"最长连续序列"
],
"children": [],
"export": [
"solution.json"
],
"title": "最长连续序列"
}
\ No newline at end of file
<p>给定一个未排序的整数数组 <code>nums</code> ,找出数字连续的最长序列(不要求序列元素在原数组中连续)的长度。</p>
<p>请你设计并实现时间复杂度为 <code>O(n)</code><em> </em>的算法解决此问题。</p>
<p> </p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong>nums = [100,4,200,1,3,2]
<strong>输出:</strong>4
<strong>解释:</strong>最长数字连续序列是 <code>[1, 2, 3, 4]。它的长度为 4。</code></pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong>nums = [0,3,7,2,5,8,4,6,0,1]
<strong>输出:</strong>9
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>0 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>
</ul>
#include <vector>
#include <unordered_map>
using std::unordered_map;
using std::vector;
class Solution
{
public:
int longestConsecutive(vector<int> &num)
{
unordered_map<int, int> map;
int max{0};
for (auto i : num)
if (!map[i])
{
map[i] = map[i + 1] + map[i - 1] + 1;
map[i - map[i - 1]] = map[i + map[i + 1]] = map[i];
max = std::max(max, map[i]);
}
return max;
}
};
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "dce3e3515a4b405e8aec92b075fac20f"
}
\ No newline at end of file
# 最长连续序列
<p>给定一个未排序的整数数组 <code>nums</code> ,找出数字连续的最长序列(不要求序列元素在原数组中连续)的长度。</p>
<p>请你设计并实现时间复杂度为 <code>O(n)</code><em> </em>的算法解决此问题。</p>
<p> </p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong>nums = [100,4,200,1,3,2]
<strong>输出:</strong>4
<strong>解释:</strong>最长数字连续序列是 <code>[1, 2, 3, 4]。它的长度为 4。</code></pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong>nums = [0,3,7,2,5,8,4,6,0,1]
<strong>输出:</strong>9
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>0 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>
</ul>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
Solution sol;
int res;
vector<int> vec = {0, 3, 7, 2, 5, 8, 4, 6, 0, 1};
res = sol.longestSequence(vec);
cout << res;
return 0;
}
```
## 答案
```cpp
class Solution
{
public:
int longestConsecutive(vector<int> &nums)
{
unordered_set<int> hash;
for (const int &num : nums)
{
hash.insert(num);
}
int ans = 0;
while (!hash.empty())
{
int cur = *(hash.begin());
hash.erase(cur);
int next = cur + 1, prev = cur - 1;
while (hash.count(next))
{
hash.erase(next++);
}
while (hash.count(prev))
{
hash.erase(prev--);
}
ans = max(ans, next - prev);
}
return ans;
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
int longestConsecutive(vector<int> &nums)
{
unordered_map<int, int> mp;
int l = 0, r = 0, res = 0, len = 0;
for (int num : nums)
{
if (!mp[num])
{
l = mp[num - 1];
r = mp[num + 1];
len = l + r + 1;
res = max(res, len);
mp[num] = len;
mp[num - l] = len;
mp[num + r] = len;
}
}
return res;
}
};
```
### B
```cpp
class Solution
{
struct DisJointSet
{
vector<int> _id;
vector<int> _size;
int max_size;
int _count;
DisJointSet(int Num)
{
for (int i = 0; i < Num; i++)
{
_id.emplace_back(i);
_size.emplace_back(1);
}
_count = Num;
max_size = 1;
}
int find_(int p)
{
while (p != _id[p])
{
_id[p] = _id[_id[p]];
p = _id[p];
}
return p;
}
void _union(int p, int q)
{
int i = find_(p);
int j = find_(q);
if (i == j)
return;
if (_size[i] > _size[j])
{
_id[j] = i;
_size[i] += _size[j];
max_size = max(max_size, _size[i]);
}
else
{
_id[i] = j;
_size[j] += _size[i];
max_size = max(max_size, _size[j]);
}
_count--;
}
};
public:
int longestConsecutive(vector<int> &nums)
{
if (nums.size() == 0)
return 0;
DisJointSet disJointSet(nums.size());
unordered_set<int> nums_set;
unordered_map<int, int> nums_disJointSetID_map;
for (int i = 0; i < nums.size(); i++)
{
if (nums_set.find(nums[i]) != nums_set.end())
continue;
nums_set.insert(nums[i]);
nums_disJointSetID_map[nums[i]] = i;
if (nums_set.find(nums[i] - 1) != nums_set.end())
{
disJointSet._union(nums_disJointSetID_map[nums[i]], nums_disJointSetID_map[nums[i] - 1]);
}
if (nums_set.find(nums[i] + 1) != nums_set.end())
{
disJointSet._union(nums_disJointSetID_map[nums[i]], nums_disJointSetID_map[nums[i] + 1]);
}
}
return disJointSet.max_size;
}
};
```
### C
```cpp
class Solution
{
public:
int longestConsecutive(vector<int> &vec)
{
set<int> s;
for (int elem : vec)
s.insert(elem);
int longest = 0;
int cnt = 1;
for (auto e : s)
{
if (s.find(e + 1) != s.end())
{
cnt++;
}
else
{
cnt = 1;
}
longest = max(longest, cnt);
}
return longest;
}
};
```
{
"node_id": "algorithm-d221fe9f0a114efdbd615b8cba03e7fc",
"keywords": [
"leetcode",
"被围绕的区域"
],
"children": [],
"export": [
"solution.json"
],
"title": "被围绕的区域"
}
\ No newline at end of file
给你一个 <code>m x n</code> 的矩阵 <code>board</code> ,由若干字符 <code>'X'</code><code>'O'</code> ,找到所有被 <code>'X'</code> 围绕的区域,并将这些区域里所有的 <code>'O'</code><code>'X'</code> 填充。
<div class="original__bRMd">
<div>
<p> </p>
<p><strong>示例 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/xogrid.jpg" style="width: 550px; height: 237px;" />
<pre>
<strong>输入:</strong>board = [["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]]
<strong>输出:</strong>[["X","X","X","X"],["X","X","X","X"],["X","X","X","X"],["X","O","X","X"]]
<strong>解释:</strong>被围绕的区间不会存在于边界上,换句话说,任何边界上的 <code>'O'</code> 都不会被填充为 <code>'X'</code>。 任何不在边界上,或不与边界上的 <code>'O'</code> 相连的 <code>'O'</code> 最终都会被填充为 <code>'X'</code>。如果两个元素在水平或垂直方向相邻,则称它们是“相连”的。
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong>board = [["X"]]
<strong>输出:</strong>[["X"]]
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>m == board.length</code></li>
<li><code>n == board[i].length</code></li>
<li><code>1 <= m, n <= 200</code></li>
<li><code>board[i][j]</code><code>'X'</code><code>'O'</code></li>
</ul>
</div>
</div>
class Solution
{
public:
int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}, n, m;
void dfs(int row, int col, vector<vector<char>> &board)
{
board[row][col] = 'o';
for (int i = 0; i < 4; ++i)
if (row + dx[i] >= 0 && row + dx[i] < n && col + dy[i] >= 0 && col + dy[i] < m && board[row + dx[i]][col + dy[i]] == 'O')
dfs(row + dx[i], col + dy[i], board);
}
void solve(vector<vector<char>> &board)
{
n = board.size(), m = n ? board[0].size() : 0;
if (!(m & n))
return;
for (int i = 0; i < n; ++i)
{
if (board[i][0] == 'O')
dfs(i, 0, board);
if (board[i][m - 1] == 'O')
dfs(i, m - 1, board);
}
for (int j = 0; j < m; ++j)
{
if (board[0][j] == 'O')
dfs(0, j, board);
if (board[n - 1][j] == 'O')
dfs(n - 1, j, board);
}
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j)
if (board[i][j] == 'O')
board[i][j] = 'X';
else if (board[i][j] == 'o')
board[i][j] = 'O';
}
};
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a2608cf9adcf469d86ac1874392f6288"
}
\ No newline at end of file
# 被围绕的区域
给你一个 <code>m x n</code> 的矩阵 <code>board</code> ,由若干字符 <code>'X'</code><code>'O'</code> ,找到所有被 <code>'X'</code> 围绕的区域,并将这些区域里所有的 <code>'O'</code><code>'X'</code> 填充。
<div class="original__bRMd">
<div>
<p> </p>
<p><strong>示例 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/xogrid.jpg" style="width: 550px; height: 237px;" />
<pre>
<strong>输入:</strong>board = [["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]]
<strong>输出:</strong>[["X","X","X","X"],["X","X","X","X"],["X","X","X","X"],["X","O","X","X"]]
<strong>解释:</strong>被围绕的区间不会存在于边界上,换句话说,任何边界上的 <code>'O'</code> 都不会被填充为 <code>'X'</code>。 任何不在边界上,或不与边界上的 <code>'O'</code> 相连的 <code>'O'</code> 最终都会被填充为 <code>'X'</code>。如果两个元素在水平或垂直方向相邻,则称它们是“相连”的。
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong>board = [["X"]]
<strong>输出:</strong>[["X"]]
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>m == board.length</code></li>
<li><code>n == board[i].length</code></li>
<li><code>1 <= m, n <= 200</code></li>
<li><code>board[i][j]</code><code>'X'</code><code>'O'</code></li>
</ul>
</div>
</div>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
Solution sol;
vector<vector<char>> board = {{'X', 'X', 'X', 'X'}, {'X', 'O', 'O', 'X'}, {'X', 'X', 'O', 'X'}, {'X', 'O', 'X', 'X'}};
sol.solve(board);
for (auto i : board)
{
for (auto j : i)
cout << j << " ";
cout << endl;
}
return 0;
}
```
## 答案
```cpp
class Solution
{
public:
vector<vector<bool>> st;
int m, n;
void bfs(vector<vector<char>> &board, int a, int b)
{
int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
st[a][b] = true;
queue<pair<int, int>> q;
q.push(make_pair(a, b));
while (q.size())
{
pair<int, int> t = q.front();
q.pop();
for (int i = 0; i < 4; i++)
{
int x = dx[i] + t.first, y = dy[i] + t.second;
if (x >= 0 && x < m && y >= 0 && y < n && board[x][y] == 'O' && !st[x][y])
{
q.push(make_pair(x, y));
st[x][y] = true;
}
}
}
}
void solve(vector<vector<char>> &board)
{
if (!board.size())
return;
m = board.size(), n = board[0].size();
st = vector<vector<bool>>(m, vector<bool>(n, false));
for (int i = 0; i < m; i++)
{
if (board[i][0] == 'O')
bfs(board, i, 0);
if (board[i][n] == 'O')
bfs(board, i, n - 1);
}
for (int i = 0; i < n; i++)
{
if (board[0][i] == 'O')
bfs(board, 0, i);
if (board[m][i] == 'O')
bfs(board, m - 1, i);
}
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
if (!st[i][j])
board[i][j] = 'X';
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
int n, m;
void dfs(vector<vector<char>> &board, int x, int y)
{
if (x < 0 || y < 0 || x >= m || y >= n || board[x][y] != 'O')
return;
board[x][y] = 'A';
dfs(board, x + 1, y);
dfs(board, x, y + 1);
dfs(board, x - 1, y);
dfs(board, x, y - 1);
}
void solve(vector<vector<char>> &board)
{
m = board.size();
if (m == 0)
return;
n = board[0].size();
for (int i = 0; i < m; i++)
{
dfs(board, i, 0);
dfs(board, i, n - 1);
}
for (int i = 1; i < n - 1; i++)
{
dfs(board, 0, i);
dfs(board, m - 1, i);
}
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
if (board[i][j] == 'A')
board[i][j] = 'O';
else if (board[i][j] == 'O')
board[i][j] = 'X';
}
}
}
};
```
### B
```cpp
class Solution
{
public:
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
queue<pair<int, int>> s;
void solve(vector<vector<char>> &board)
{
int n = board.size();
if (n <= 2)
return;
int m = board[0].size();
if (m <= 2)
return;
for (int i = 0; i < m; i++)
{
if (board[0][i] == 'O')
s.push({0, i});
if (board[n - 1][i] == 'O')
s.push({n - 1, i});
}
for (int i = 1; i < n - 1; i++)
{
if (board[i][0] == 'O')
s.push({i, 0});
if (board[i][m - 1] == 'O')
s.push({i, m - 1});
}
while (!s.empty())
{
int x = s.front().first, y = s.front().second;
board[x][y] = '#';
s.pop();
for (int i = 0; i < 4; i++)
{
int mx = x + dx[i], my = y + dy[i];
if (mx < 0 || my < 0 || mx >= n || my >= m || board[mx][my] != 'O')
{
continue;
}
s.push({mx, my});
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (board[i][j] == '#')
board[i][j] = 'O';
else if (board[i][j] == 'O')
board[i][j] = 'X';
}
}
}
};
```
### C
```cpp
class Solution
{
public:
void dfs(vector<vector<char>> &board, int row, int col)
{
if (row < 0 || row >= board.size() || col < 0 || col >= board[0].size())
return;
if (board[row][col] != 'O')
return;
board[row][col] = '+';
dfs(board, row + 1, col);
dfs(board, row, col + 1);
dfs(board, row - 1, col);
dfs(board, row, col - 1);
}
void solve(vector<vector<char>> &board)
{
if (board.size() <= 1 || board[0].size() <= 2)
return;
for (int i = 0; i < board.size(); i++)
{
if (board[i][0] == 'O')
dfs(board, i, 0);
if (board[i][board[0].size() - 1] == 'O')
dfs(board, i, board[0].size() - 1);
}
for (int i = 0; i < board[0].size(); i++)
{
if (board[0][i] == 'O')
dfs(board, 0, i);
if (board[board.size() - 1][i] == 'O')
dfs(board, board.size() - 1, i);
}
for (int i = 0; i < board.size(); i++)
{
for (int j = 0; j < board[0].size(); j++)
{
if (board[i][j] == '+')
board[i][j] = 'O';
else if (board[i][j] == 'O')
board[i][j] = 'X';
}
}
}
};
```
{
"node_id": "algorithm-15e7a6d4c7da4ed682782b7b4b9761d2",
"keywords": [
"leetcode",
"路径总和"
],
"children": [],
"export": [
"solution.json"
],
"title": "路径总和"
}
\ No newline at end of file
<p>给你二叉树的根节点 <code>root</code> 和一个表示目标和的整数 <code>targetSum</code> ,判断该树中是否存在 <strong>根节点到叶子节点</strong> 的路径,这条路径上所有节点值相加等于目标和 <code>targetSum</code></p>
<p><strong>叶子节点</strong> 是指没有子节点的节点。</p>
<p> </p>
<p><strong>示例 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/01/18/pathsum1.jpg" style="width: 500px; height: 356px;" />
<pre>
<strong>输入:</strong>root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22
<strong>输出:</strong>true
</pre>
<p><strong>示例 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/01/18/pathsum2.jpg" />
<pre>
<strong>输入:</strong>root = [1,2,3], targetSum = 5
<strong>输出:</strong>false
</pre>
<p><strong>示例 3:</strong></p>
<pre>
<strong>输入:</strong>root = [1,2], targetSum = 0
<strong>输出:</strong>false
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li>树中节点的数目在范围 <code>[0, 5000]</code></li>
<li><code>-1000 <= Node.val <= 1000</code></li>
<li><code>-1000 <= targetSum <= 1000</code></li>
</ul>
#include <cstddef>
struct TreeNode
{
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
class Solution
{
public:
bool hasPathSum(TreeNode *root, int sum)
{
if (!root)
return false;
if (!root->left and !root->right and sum - root->val == 0)
return true;
return hasPathSum(root->left, sum - root->val) or hasPathSum(root->right, sum - root->val);
}
};
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "544c6d3b7e0d4116b27d5fdb8691a522"
}
\ No newline at end of file
# 路径总和
<p>给你二叉树的根节点 <code>root</code> 和一个表示目标和的整数 <code>targetSum</code> ,判断该树中是否存在 <strong>根节点到叶子节点</strong> 的路径,这条路径上所有节点值相加等于目标和 <code>targetSum</code></p>
<p><strong>叶子节点</strong> 是指没有子节点的节点。</p>
<p> </p>
<p><strong>示例 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/01/18/pathsum1.jpg" style="width: 500px; height: 356px;" />
<pre>
<strong>输入:</strong>root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22
<strong>输出:</strong>true
</pre>
<p><strong>示例 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/01/18/pathsum2.jpg" />
<pre>
<strong>输入:</strong>root = [1,2,3], targetSum = 5
<strong>输出:</strong>false
</pre>
<p><strong>示例 3:</strong></p>
<pre>
<strong>输入:</strong>root = [1,2], targetSum = 0
<strong>输出:</strong>false
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li>树中节点的数目在范围 <code>[0, 5000]</code></li>
<li><code>-1000 <= Node.val <= 1000</code></li>
<li><code>-1000 <= targetSum <= 1000</code></li>
</ul>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
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 hasPathSum(TreeNode *root, int sum)
{
if (root == NULL)
{
return false;
}
vector<TreeNode *> node_stack;
vector<int> sum_stack;
node_stack.push_back(root);
sum_stack.push_back(sum - root->val);
TreeNode *node;
int curr_sum;
while (!node_stack.empty())
{
node = node_stack.back();
node_stack.pop_back();
curr_sum = sum_stack.back();
sum_stack.pop_back();
if ((node->right == NULL) && (node->left == NULL) && (curr_sum == 0))
{
return true;
}
if (node->right != NULL)
{
node_stack.push_back(node->right);
sum_stack.push_back(curr_sum - node->right->val);
}
if (node->left != NULL)
{
node_stack.push_back(node->left);
sum_stack.push_back(curr_sum - node->left->val);
}
}
return false;
}
};
```
### B
```cpp
class Solution
{
public:
bool hasPathSum(TreeNode *root, int sum)
{
if (root == NULL)
return false;
stack<pair<TreeNode *, int>> s;
s.push(make_pair(root, sum));
TreeNode *node = root;
int currSum;
while (!s.empty())
{
node = s.top().first;
currSum = s.top().second;
s.pop();
if (node->left == NULL && node->right == NULL && node->val == currSum)
return true;
if (node->right)
s.push(make_pair(node->right, currSum - node->val));
if (node->left)
s.push(make_pair(node->left, currSum - node->val));
}
return false;
}
};
```
### C
```cpp
class Solution
{
public:
bool hasPathSum(TreeNode *root, int sum)
{
if (!root)
return false;
if (!root->left && !root->right && root->val == sum)
return true;
return hasPathSum(root->left, sum - root->val) || hasPathSum(root->right, sum - root->val);
}
};
```
{
"node_id": "algorithm-32f257cc9a114a4cb092581b3a017d74",
"keywords": [
"leetcode",
"路径总和 II"
],
"children": [],
"export": [
"solution.json"
],
"title": "路径总和 II"
}
\ No newline at end of file
<p>给你二叉树的根节点 <code>root</code> 和一个整数目标和 <code>targetSum</code> ,找出所有 <strong>从根节点到叶子节点</strong> 路径总和等于给定目标和的路径。</p>
<p><strong>叶子节点</strong> 是指没有子节点的节点。</p>
<div class="original__bRMd">
<div>
<p> </p>
<p><strong>示例 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/01/18/pathsumii1.jpg" style="width: 500px; height: 356px;" />
<pre>
<strong>输入:</strong>root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22
<strong>输出:</strong>[[5,4,11,2],[5,8,4,5]]
</pre>
<p><strong>示例 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/01/18/pathsum2.jpg" style="width: 212px; height: 181px;" />
<pre>
<strong>输入:</strong>root = [1,2,3], targetSum = 5
<strong>输出:</strong>[]
</pre>
<p><strong>示例 3:</strong></p>
<pre>
<strong>输入:</strong>root = [1,2], targetSum = 0
<strong>输出:</strong>[]
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li>树中节点总数在范围 <code>[0, 5000]</code></li>
<li><code>-1000 <= Node.val <= 1000</code></li>
<li><code>-1000 <= targetSum <= 1000</code></li>
</ul>
</div>
</div>
#include <vector>
#include <cstddef>
#include <stack>
#include <algorithm>
using std::vector;
struct TreeNode
{
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
class Solution
{
public:
vector<vector<int>> pathSum(TreeNode *root, int sum)
{
vector<vector<int>> ret;
vector<int> path;
pathSum(root, sum, path, ret);
return ret;
}
void pathSum(TreeNode *root, int sum, vector<int> &path, vector<vector<int>> &ret)
{
if (!root)
return;
path.push_back(root->val);
if (!root->left && !root->right && root->val == sum)
ret.push_back(path);
if (root->left)
pathSum(root->left, sum - root->val, path, ret);
if (root->right)
pathSum(root->right, sum - root->val, path, ret);
path.pop_back();
}
};
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "cebd88413a964aeca882afdf79cb545a"
}
\ No newline at end of file
# 路径总和 II
<p>给你二叉树的根节点 <code>root</code> 和一个整数目标和 <code>targetSum</code> ,找出所有 <strong>从根节点到叶子节点</strong> 路径总和等于给定目标和的路径。</p>
<p><strong>叶子节点</strong> 是指没有子节点的节点。</p>
<div class="original__bRMd">
<div>
<p> </p>
<p><strong>示例 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/01/18/pathsumii1.jpg" style="width: 500px; height: 356px;" />
<pre>
<strong>输入:</strong>root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22
<strong>输出:</strong>[[5,4,11,2],[5,8,4,5]]
</pre>
<p><strong>示例 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/01/18/pathsum2.jpg" style="width: 212px; height: 181px;" />
<pre>
<strong>输入:</strong>root = [1,2,3], targetSum = 5
<strong>输出:</strong>[]
</pre>
<p><strong>示例 3:</strong></p>
<pre>
<strong>输入:</strong>root = [1,2], targetSum = 0
<strong>输出:</strong>[]
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li>树中节点总数在范围 <code>[0, 5000]</code></li>
<li><code>-1000 <= Node.val <= 1000</code></li>
<li><code>-1000 <= targetSum <= 1000</code></li>
</ul>
</div>
</div>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
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:
vector<vector<int>> pathSum(TreeNode *root, int sum)
{
int pos = 0;
vector<int> path;
vector<vector<int>> result;
dfs(root, sum, pos, path, result);
return result;
}
private:
void dfs(TreeNode *root, int sum, int &pos, vector<int> &path, vector<vector<int>> &result)
{
if (root == NULL)
return;
pos += root->val;
path.push_back(root->val);
if (!root->left && !root->right && pos == sum)
result.push_back(path);
dfs(root->left, sum, pos, path, result);
dfs(root->right, sum, pos, path, result);
path.pop_back();
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
void find(TreeNode *node, vector<vector<int>> &result, vector<int> &path, int sum)
{
path.push_back(node->val);
if (node->left == NULL && node->right == NULL && sum == node->val)
{
result.push_back(path);
return;
}
if (node->left != NULL)
{
find(node->left, result, path, sum - node->val);
path.pop_back();
}
if (node->right != NULL)
{
find(node->right, result, path, sum - node->val);
path.pop_back();
}
}
vector<vector<int>> pathSum(TreeNode *root, int sum)
{
vector<vector<int>> result;
vector<int> path;
if (root == NULL)
{
return result;
}
find(root, result, path, sum);
return result;
}
};
```
### B
```cpp
class Solution
{
public:
vector<vector<int>> pathSum(TreeNode *root, int sum)
{
vector<vector<int>> res;
if (!root)
return res;
vector<int> temp;
dfs(root, res, temp, sum);
return res;
}
void dfs(TreeNode *root, vector<vector<int>> &res, vector<int> temp, int sum)
{
temp.push_back(root->val);
if (!root->left && !root->right && 0 == sum - root->val)
res.push_back(temp);
if (root->left)
dfs(root->left, res, temp, sum - root->val);
if (root->right)
dfs(root->right, res, temp, sum - root->val);
}
};
```
### C
```cpp
class Solution
{
public:
vector<vector<int>> pathSum(TreeNode *root, int targetSum)
{
DFS(root, targetSum);
return result;
}
void DFS(TreeNode *root, int targetSum)
{
if (root == nullptr)
return;
tmp_path.emplace_back(root->val);
targetSum -= root->val;
if (root->left == nullptr && root->right == nullptr && targetSum == 0)
{
result.emplace_back(tmp_path);
}
DFS(root->left, targetSum);
DFS(root->right, targetSum);
tmp_path.pop_back();
}
private:
vector<vector<int>> result;
vector<int> tmp_path;
};
```
{
"node_id": "algorithm-bfd16b54a79348af9077cc46f46e5169",
"keywords": [
"leetcode",
"二叉搜索树迭代器"
],
"children": [],
"export": [
"solution.json"
],
"title": "二叉搜索树迭代器"
}
\ No newline at end of file
实现一个二叉搜索树迭代器类<code>BSTIterator</code> ,表示一个按中序遍历二叉搜索树(BST)的迭代器:
<div class="original__bRMd">
<div>
<ul>
<li><code>BSTIterator(TreeNode root)</code> 初始化 <code>BSTIterator</code> 类的一个对象。BST 的根节点 <code>root</code> 会作为构造函数的一部分给出。指针应初始化为一个不存在于 BST 中的数字,且该数字小于 BST 中的任何元素。</li>
<li><code>boolean hasNext()</code> 如果向指针右侧遍历存在数字,则返回 <code>true</code> ;否则返回 <code>false</code></li>
<li><code>int next()</code>将指针向右移动,然后返回指针处的数字。</li>
</ul>
<p>注意,指针初始化为一个不存在于 BST 中的数字,所以对 <code>next()</code> 的首次调用将返回 BST 中的最小元素。</p>
</div>
</div>
<p>你可以假设 <code>next()</code> 调用总是有效的,也就是说,当调用 <code>next()</code> 时,BST 的中序遍历中至少存在一个下一个数字。</p>
<p> </p>
<p><strong>示例:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2018/12/25/bst-tree.png" style="width: 189px; height: 178px;" />
<pre>
<strong>输入</strong>
["BSTIterator", "next", "next", "hasNext", "next", "hasNext", "next", "hasNext", "next", "hasNext"]
[[[7, 3, 15, null, null, 9, 20]], [], [], [], [], [], [], [], [], []]
<strong>输出</strong>
[null, 3, 7, true, 9, true, 15, true, 20, false]
<strong>解释</strong>
BSTIterator bSTIterator = new BSTIterator([7, 3, 15, null, null, 9, 20]);
bSTIterator.next(); // 返回 3
bSTIterator.next(); // 返回 7
bSTIterator.hasNext(); // 返回 True
bSTIterator.next(); // 返回 9
bSTIterator.hasNext(); // 返回 True
bSTIterator.next(); // 返回 15
bSTIterator.hasNext(); // 返回 True
bSTIterator.next(); // 返回 20
bSTIterator.hasNext(); // 返回 False
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li>树中节点的数目在范围 <code>[1, 10<sup>5</sup>]</code></li>
<li><code>0 <= Node.val <= 10<sup>6</sup></code></li>
<li>最多调用 <code>10<sup>5</sup></code><code>hasNext</code><code>next</code> 操作</li>
</ul>
<p> </p>
<p><strong>进阶:</strong></p>
<ul>
<li>你可以设计一个满足下述条件的解决方案吗?<code>next()</code><code>hasNext()</code> 操作均摊时间复杂度为 <code>O(1)</code> ,并使用 <code>O(h)</code> 内存。其中 <code>h</code> 是树的高度。</li>
</ul>
struct TreeNode
{
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
class BSTIterator
{
public:
BSTIterator(TreeNode *root)
{
TreeNode *cur = root;
while (cur)
{
st.push(cur);
cur = cur->left;
}
}
/** @return whether we have a next smallest number */
bool hasNext()
{
return !st.empty();
}
/** @return the next smallest number */
int next()
{
TreeNode *next = st.top();
TreeNode *cur = next->right;
st.pop();
while (cur)
{
st.push(cur);
cur = cur->left;
}
return next->val;
}
private:
stack<TreeNode *> st;
};
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "860327443b0d4f12a8fb51c7d674c3e9"
}
\ No newline at end of file
# 二叉搜索树迭代器
实现一个二叉搜索树迭代器类<code>BSTIterator</code> ,表示一个按中序遍历二叉搜索树(BST)的迭代器:
<div class="original__bRMd">
<div>
<ul>
<li><code>BSTIterator(TreeNode root)</code> 初始化 <code>BSTIterator</code> 类的一个对象。BST 的根节点 <code>root</code> 会作为构造函数的一部分给出。指针应初始化为一个不存在于 BST 中的数字,且该数字小于 BST 中的任何元素。</li>
<li><code>boolean hasNext()</code> 如果向指针右侧遍历存在数字,则返回 <code>true</code> ;否则返回 <code>false</code></li>
<li><code>int next()</code>将指针向右移动,然后返回指针处的数字。</li>
</ul>
<p>注意,指针初始化为一个不存在于 BST 中的数字,所以对 <code>next()</code> 的首次调用将返回 BST 中的最小元素。</p>
</div>
</div>
<p>你可以假设 <code>next()</code> 调用总是有效的,也就是说,当调用 <code>next()</code> 时,BST 的中序遍历中至少存在一个下一个数字。</p>
<p> </p>
<p><strong>示例:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2018/12/25/bst-tree.png" style="width: 189px; height: 178px;" />
<pre>
<strong>输入</strong>
["BSTIterator", "next", "next", "hasNext", "next", "hasNext", "next", "hasNext", "next", "hasNext"]
[[[7, 3, 15, null, null, 9, 20]], [], [], [], [], [], [], [], [], []]
<strong>输出</strong>
[null, 3, 7, true, 9, true, 15, true, 20, false]
<strong>解释</strong>
BSTIterator bSTIterator = new BSTIterator([7, 3, 15, null, null, 9, 20]);
bSTIterator.next(); // 返回 3
bSTIterator.next(); // 返回 7
bSTIterator.hasNext(); // 返回 True
bSTIterator.next(); // 返回 9
bSTIterator.hasNext(); // 返回 True
bSTIterator.next(); // 返回 15
bSTIterator.hasNext(); // 返回 True
bSTIterator.next(); // 返回 20
bSTIterator.hasNext(); // 返回 False
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li>树中节点的数目在范围 <code>[1, 10<sup>5</sup>]</code></li>
<li><code>0 <= Node.val <= 10<sup>6</sup></code></li>
<li>最多调用 <code>10<sup>5</sup></code><code>hasNext</code><code>next</code> 操作</li>
</ul>
<p> </p>
<p><strong>进阶:</strong></p>
<ul>
<li>你可以设计一个满足下述条件的解决方案吗?<code>next()</code><code>hasNext()</code> 操作均摊时间复杂度为 <code>O(1)</code> ,并使用 <code>O(h)</code> 内存。其中 <code>h</code> 是树的高度。</li>
</ul>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
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
/**
* Your BSTIterator object will be instantiated and called as such:
* BSTIterator* obj = new BSTIterator(root);
* int param_1 = obj->next();
* bool param_2 = obj->hasNext();
*/
```
## 答案
```cpp
class BSTIterator
{
private:
void traverse(TreeNode *root, vector<int> &res)
{
if (root == nullptr)
{
return;
}
traverse(root->right, res);
traverse(root->left, res);
res.push_back(root->val);
}
vector<int> inorder(TreeNode *root)
{
vector<int> res;
traverse(root, res);
return res;
}
vector<int> arr;
int idx;
public:
BSTIterator(TreeNode *root) : idx(0), arr(inorder(root))
{
}
int next()
{
return arr[idx++];
}
bool hasNext()
{
return idx < arr.size();
}
};
```
## 选项
### A
```cpp
class BSTIterator
{
private:
void inorder(TreeNode *root, vector<int> &vec)
{
if (!root)
return;
inorder(root->left, vec);
vec.emplace_back(root->val);
inorder(root->right, vec);
}
vector<int> inorderTraversal(TreeNode *root)
{
vector<int> ret;
inorder(root, ret);
return ret;
}
vector<int> buf;
size_t idx;
public:
BSTIterator(TreeNode *root)
{
idx = 0;
buf = inorderTraversal(root);
}
int next()
{
return buf[idx++];
}
bool hasNext()
{
return idx < buf.size();
}
};
```
### B
```cpp
class BSTIterator
{
public:
stack<TreeNode *> treeMin;
BSTIterator(TreeNode *root)
{
TreeNode *t = root;
while (t)
{
treeMin.push(t);
t = t->left;
}
}
/** @return the next smallest number */
int next()
{
TreeNode *tmp = treeMin.top();
int res = tmp->val;
treeMin.pop();
tmp = tmp->right;
while (tmp)
{
treeMin.push(tmp);
tmp = tmp->left;
}
return res;
}
/** @return whether we have a next smallest number */
bool hasNext()
{
if (treeMin.empty())
return false;
else
return true;
}
};
```
### C
```cpp
class BSTIterator
{
public:
queue<int> q;
BSTIterator(TreeNode *root)
{
inorder(root, q);
}
void inorder(TreeNode *root, queue<int> &q)
{
if (root == NULL)
return;
inorder(root->left, q);
q.push(root->val);
inorder(root->right, q);
}
/** @return the next smallest number */
int next()
{
int tmp = q.front();
q.pop();
return tmp;
}
/** @return whether we have a next smallest number */
bool hasNext()
{
if (q.empty())
return false;
else
return true;
}
};
```
{
"node_id": "algorithm-14d4d8e793b84c1cb3efe42497cfb78c",
"keywords": [
"leetcode",
"实现 Trie (前缀树)"
],
"children": [],
"export": [
"solution.json"
],
"title": "实现 Trie (前缀树)"
}
\ No newline at end of file
<p><strong><a href="https://baike.baidu.com/item/字典树/9825209?fr=aladdin" target="_blank">Trie</a></strong>(发音类似 "try")或者说 <strong>前缀树</strong> 是一种树形数据结构,用于高效地存储和检索字符串数据集中的键。这一数据结构有相当多的应用情景,例如自动补完和拼写检查。</p>
<p>请你实现 Trie 类:</p>
<ul>
<li><code>Trie()</code> 初始化前缀树对象。</li>
<li><code>void insert(String word)</code> 向前缀树中插入字符串 <code>word</code></li>
<li><code>boolean search(String word)</code> 如果字符串 <code>word</code> 在前缀树中,返回 <code>true</code>(即,在检索之前已经插入);否则,返回 <code>false</code></li>
<li><code>boolean startsWith(String prefix)</code> 如果之前已经插入的字符串 <code>word</code> 的前缀之一为 <code>prefix</code> ,返回 <code>true</code> ;否则,返回 <code>false</code></li>
</ul>
<p> </p>
<p><strong>示例:</strong></p>
<pre>
<strong>输入</strong>
["Trie", "insert", "search", "search", "startsWith", "insert", "search"]
[[], ["apple"], ["apple"], ["app"], ["app"], ["app"], ["app"]]
<strong>输出</strong>
[null, null, true, false, true, null, true]
<strong>解释</strong>
Trie trie = new Trie();
trie.insert("apple");
trie.search("apple"); // 返回 True
trie.search("app"); // 返回 False
trie.startsWith("app"); // 返回 True
trie.insert("app");
trie.search("app"); // 返回 True
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= word.length, prefix.length <= 2000</code></li>
<li><code>word</code><code>prefix</code> 仅由小写英文字母组成</li>
<li><code>insert</code><code>search</code><code>startsWith</code> 调用次数 <strong>总计</strong> 不超过 <code>3 * 10<sup>4</sup></code></li>
</ul>
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "fc412fd05a0244d0a8cd4d86cf9e775b"
}
\ No newline at end of file
# 实现 Trie (前缀树)
<p><strong><a href="https://baike.baidu.com/item/字典树/9825209?fr=aladdin" target="_blank">Trie</a></strong>(发音类似 "try")或者说 <strong>前缀树</strong> 是一种树形数据结构,用于高效地存储和检索字符串数据集中的键。这一数据结构有相当多的应用情景,例如自动补完和拼写检查。</p>
<p>请你实现 Trie 类:</p>
<ul>
<li><code>Trie()</code> 初始化前缀树对象。</li>
<li><code>void insert(String word)</code> 向前缀树中插入字符串 <code>word</code></li>
<li><code>boolean search(String word)</code> 如果字符串 <code>word</code> 在前缀树中,返回 <code>true</code>(即,在检索之前已经插入);否则,返回 <code>false</code></li>
<li><code>boolean startsWith(String prefix)</code> 如果之前已经插入的字符串 <code>word</code> 的前缀之一为 <code>prefix</code> ,返回 <code>true</code> ;否则,返回 <code>false</code></li>
</ul>
<p> </p>
<p><strong>示例:</strong></p>
<pre>
<strong>输入</strong>
["Trie", "insert", "search", "search", "startsWith", "insert", "search"]
[[], ["apple"], ["apple"], ["app"], ["app"], ["app"], ["app"]]
<strong>输出</strong>
[null, null, true, false, true, null, true]
<strong>解释</strong>
Trie trie = new Trie();
trie.insert("apple");
trie.search("apple"); // 返回 True
trie.search("app"); // 返回 False
trie.startsWith("app"); // 返回 True
trie.insert("app");
trie.search("app"); // 返回 True
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= word.length, prefix.length <= 2000</code></li>
<li><code>word</code><code>prefix</code> 仅由小写英文字母组成</li>
<li><code>insert</code><code>search</code><code>startsWith</code> 调用次数 <strong>总计</strong> 不超过 <code>3 * 10<sup>4</sup></code></li>
</ul>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
```
## 答案
```cpp
class TrieNode
{
public:
bool end_with;
TrieNode *next[26];
TrieNode()
{
end_with = false;
memset(next, 0, sizeof(next));
}
};
class Trie
{
TrieNode root;
public:
/** Initialize your data structure here. */
Trie() {}
/** Inserts a word into the trie. */
void insert(string word)
{
TrieNode *node = &root;
for (int i = 0; i < word.size(); i++)
{
int c = word[i] - 'a';
node->next[c] = new TrieNode();
node = node->next[c];
}
node->end_with = true;
}
/** Returns if the word is in the trie. */
bool search(string word)
{
TrieNode *node = &root;
for (int i = 0; i < word.size(); i++)
{
if (node->next[word[i] - 'a'] != NULL)
node = node->next[word[i] - 'a'];
else
return false;
}
return (node->end_with) ? true : false;
}
/** Returns if there is any word in the trie that starts with the given prefix. */
bool startsWith(string prefix)
{
TrieNode *node = &root;
for (int i = 0; i < prefix.size(); i++)
{
if (node->next[prefix[i] - 'a'] != NULL)
node = node->next[prefix[i] - 'a'];
else
return false;
}
return true;
}
};
```
## 选项
### A
```cpp
struct TrieNode
{
bool isEnd = false;
TrieNode *children[26] = {NULL};
};
class Trie
{
public:
Trie() : root(new TrieNode) {}
void insert(string word)
{
TrieNode *p = root;
for (int i = 0; i < word.size(); ++i)
{
int idx = word[i] - 'a';
if (p->children[idx] == NULL)
p->children[idx] = new TrieNode;
p = p->children[idx];
}
p->isEnd = true;
}
bool search(string word)
{
auto p = root;
for (int i = 0; i < word.size(); ++i)
{
int idx = word[i] - 'a';
if (p->children[idx] == NULL)
return false;
p = p->children[idx];
}
return p->isEnd;
}
bool startsWith(string prefix)
{
auto p = root;
for (int i = 0; i < prefix.size(); ++i)
{
int idx = prefix[i] - 'a';
if (p->children[idx] == NULL)
return false;
p = p->children[idx];
}
return true;
}
private:
TrieNode *root;
};
```
### B
```cpp
struct TrieNode
{
const static int MaxBranchNum = 26;
char data;
bool isEnd = false;
vector<TrieNode *> children = vector<TrieNode *>(26);
TrieNode(char data) : data(data){};
};
class Trie
{
public:
Trie() : root(new TrieNode('/')) {}
void insert(string word)
{
TrieNode *p = root;
for (int i = 0; i < word.size(); ++i)
{
int idx = word[i] - 'a';
if (p->children[idx] == NULL)
p->children[idx] = new TrieNode(word[i]);
p = p->children[idx];
}
p->isEnd = true;
}
bool search(string word)
{
auto p = root;
for (int i = 0; i < word.size(); ++i)
{
int idx = word[i] - 'a';
if (p->children[idx] == NULL)
return false;
p = p->children[idx];
}
return p->isEnd;
}
bool startsWith(string prefix)
{
auto p = root;
for (int i = 0; i < prefix.size(); ++i)
{
int idx = prefix[i] - 'a';
if (p->children[idx] == NULL)
return false;
p = p->children[idx];
}
return true;
}
private:
TrieNode *root;
};
```
### C
```cpp
struct Node
{
map<char, Node *> next;
bool f = false;
};
class Trie
{
public:
Node *head;
/** Initialize your data structure here. */
Trie()
{
head = new Node();
}
/** Inserts a word into the trie. */
void insert(string word)
{
Node *t = head;
for (char c : word)
{
if (t->next[c] == NULL)
{
Node *n = new Node;
t->next[c] = n;
}
t = t->next[c];
}
t->f = true;
}
/** Returns if the word is in the trie. */
bool search(string word)
{
Node *t = head;
for (char c : word)
{
if (t->next[c] == NULL)
{
return false;
}
t = t->next[c];
}
return t->f;
}
/** Returns if there is any word in the trie that starts with the given prefix. */
bool startsWith(string prefix)
{
Node *t = head;
for (char c : prefix)
{
if (t->next[c] == NULL)
{
return false;
}
t = t->next[c];
}
return true;
}
};
```
{
"node_id": "algorithm-c0fc6a20b2914daba094b822d884d76f",
"keywords": [
"leetcode",
"TinyURL 的加密与解密"
],
"children": [],
"export": [
"solution.json"
],
"title": "TinyURL 的加密与解密"
}
\ No newline at end of file
<p>TinyURL是一种URL简化服务, 比如:当你输入一个URL&nbsp;<code>https://leetcode.com/problems/design-tinyurl</code>&nbsp;时,它将返回一个简化的URL&nbsp;<code>http://tinyurl.com/4e9iAk</code>.</p>
<p>要求:设计一个 TinyURL 的加密&nbsp;<code>encode</code>&nbsp;和解密&nbsp;<code>decode</code>&nbsp;的方法。你的加密和解密算法如何设计和运作是没有限制的,你只需要保证一个URL可以被加密成一个TinyURL,并且这个TinyURL可以用解密方法恢复成原本的URL。</p>
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "4bb1610f42434348b3ea6b82290f04d3"
}
\ No newline at end of file
# TinyURL 的加密与解密
<p>TinyURL是一种URL简化服务, 比如:当你输入一个URL&nbsp;<code>https://leetcode.com/problems/design-tinyurl</code>&nbsp;时,它将返回一个简化的URL&nbsp;<code>http://tinyurl.com/4e9iAk</code>.</p>
<p>要求:设计一个 TinyURL 的加密&nbsp;<code>encode</code>&nbsp;和解密&nbsp;<code>decode</code>&nbsp;的方法。你的加密和解密算法如何设计和运作是没有限制的,你只需要保证一个URL可以被加密成一个TinyURL,并且这个TinyURL可以用解密方法恢复成原本的URL。</p>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
// Your Solution object will be instantiated and called as such:
// Solution solution;
// solution.decode(solution.encode(url));
```
## 答案
```cpp
class Solution
{
public:
map<string, string> mp;
string encode(string longUrl)
{
string str = "tinyurl" + to_string(key);
mp[str] = longUrl;
return str;
}
string decode(string shortUrl)
{
return mp[shortUrl];
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
unordered_map<string, string> hashMap;
string TINYURL_PREFIX = "http://tinyurl.com/";
string INDEX = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
string encode(string longUrl)
{
string newShortStr = "";
while (true)
{
for (int i = 0; i < 6; ++i)
{
newShortStr += INDEX[rand() % 62];
}
string resStr = TINYURL_PREFIX + newShortStr;
if (hashMap.count(resStr) == 0)
{
hashMap[resStr] = longUrl;
return resStr;
}
}
}
string decode(string shortUrl)
{
return hashMap[shortUrl];
}
};
```
### B
```cpp
class Solution
{
public:
using ull = unsigned long long;
const ull base = 11;
const string code = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ull len = code.size();
unordered_map<string, string> m;
ull hashCode(string url)
{
ull hash = 0;
for (auto c : url)
{
hash *= base;
hash += c;
}
return hash;
}
string hashToString(ull n)
{
string ans;
while (n)
{
ans += code[n % len];
n /= len;
}
return ans;
}
string encode(string longUrl)
{
string shortUrl = hashToString(hashCode(longUrl));
m[shortUrl] = longUrl;
return shortUrl;
}
string decode(string shortUrl)
{
return m[shortUrl];
}
};
```
### C
```cpp
class Solution
{
public:
unordered_map<string, string> mp;
int i = 0;
string encode(string longUrl)
{
mp[to_string(i)] = longUrl;
string res = "http://tinyurl.com/" + to_string(i++);
return res;
}
string decode(string shortUrl)
{
return mp[shortUrl.substr(19, shortUrl.size() - 19)];
}
};
```
{
"node_id": "algorithm-877445164cb3460c98afa991e4cba2d9",
"keywords": [
"leetcode",
"按要求补齐数组"
],
"children": [],
"export": [
"solution.json"
],
"title": "按要求补齐数组"
}
\ No newline at end of file
<p>给定一个已排序的正整数数组 <em>nums,</em>和一个正整数&nbsp;<em>n 。</em>&nbsp;<code>[1, n]</code>&nbsp;区间内选取任意个数字补充到&nbsp;<em>nums&nbsp;</em>中,使得&nbsp;<code>[1, n]</code>&nbsp;区间内的任何数字都可以用&nbsp;<em>nums&nbsp;</em>中某几个数字的和来表示。请输出满足上述要求的最少需要补充的数字个数。</p>
<p><strong>示例&nbsp;1:</strong></p>
<pre><strong>输入: </strong><em>nums</em> = <code>[1,3]</code>, <em>n</em> = <code>6</code>
<strong>输出: </strong>1
<strong>解释:</strong>
根据<em> nums&nbsp;</em>里现有的组合&nbsp;<code>[1], [3], [1,3]</code>,可以得出&nbsp;<code>1, 3, 4</code>
现在如果我们将&nbsp;<code>2</code>&nbsp;添加到&nbsp;<em>nums 中,</em>&nbsp;组合变为: <code>[1], [2], [3], [1,3], [2,3], [1,2,3]</code>
其和可以表示数字&nbsp;<code>1, 2, 3, 4, 5, 6</code>,能够覆盖&nbsp;<code>[1, 6]</code>&nbsp;区间里所有的数。
所以我们最少需要添加一个数字。</pre>
<p><strong>示例 2:</strong></p>
<pre><strong>输入: </strong><em>nums</em> = <code>[1,5,10]</code>, <em>n</em> = <code>20</code>
<strong>输出:</strong> 2
<strong>解释: </strong>我们需要添加&nbsp;<code>[2, 4]</code>
</pre>
<p><strong>示例&nbsp;3:</strong></p>
<pre><strong>输入: </strong><em>nums</em> = <code>[1,2,2]</code>, <em>n</em> = <code>5</code>
<strong>输出:</strong> 0
</pre>
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f2e948669b074e0894d025effeeddcb7"
}
\ No newline at end of file
# 按要求补齐数组
<p>给定一个已排序的正整数数组 <em>nums,</em>和一个正整数&nbsp;<em>n 。</em>&nbsp;<code>[1, n]</code>&nbsp;区间内选取任意个数字补充到&nbsp;<em>nums&nbsp;</em>中,使得&nbsp;<code>[1, n]</code>&nbsp;区间内的任何数字都可以用&nbsp;<em>nums&nbsp;</em>中某几个数字的和来表示。请输出满足上述要求的最少需要补充的数字个数。</p>
<p><strong>示例&nbsp;1:</strong></p>
<pre><strong>输入: </strong><em>nums</em> = <code>[1,3]</code>, <em>n</em> = <code>6</code>
<strong>输出: </strong>1
<strong>解释:</strong>
根据<em> nums&nbsp;</em>里现有的组合&nbsp;<code>[1], [3], [1,3]</code>,可以得出&nbsp;<code>1, 3, 4</code>
现在如果我们将&nbsp;<code>2</code>&nbsp;添加到&nbsp;<em>nums 中,</em>&nbsp;组合变为: <code>[1], [2], [3], [1,3], [2,3], [1,2,3]</code>
其和可以表示数字&nbsp;<code>1, 2, 3, 4, 5, 6</code>,能够覆盖&nbsp;<code>[1, 6]</code>&nbsp;区间里所有的数。
所以我们最少需要添加一个数字。</pre>
<p><strong>示例 2:</strong></p>
<pre><strong>输入: </strong><em>nums</em> = <code>[1,5,10]</code>, <em>n</em> = <code>20</code>
<strong>输出:</strong> 2
<strong>解释: </strong>我们需要添加&nbsp;<code>[2, 4]</code>
</pre>
<p><strong>示例&nbsp;3:</strong></p>
<pre><strong>输入: </strong><em>nums</em> = <code>[1,2,2]</code>, <em>n</em> = <code>5</code>
<strong>输出:</strong> 0
</pre>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
Solution sol;
vector<int> nums = {1, 5, 10};
int n = 20;
int res = sol.minPatches(nums, n);
cout << res;
return 0;
}
```
## 答案
```cpp
class Solution
{
public:
int minPatches(vector<int> &nums, int n)
{
long sum = 0;
int reti = 0;
int i = 0;
while (sum < n)
{
if (i >= nums.size())
break;
if ((sum + 1) >= nums[i])
{
sum += nums[++i];
}
else
{
int temp = sum + 1;
sum += temp;
reti++;
}
}
while (sum < n)
{
int temp = sum + 1;
sum += temp;
}
return reti;
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
int minPatches(vector<int> &nums, int n)
{
int resultCnt = 0;
int numsSize = nums.size(), index = 0;
long long head = 1;
while (head <= n)
{
if (index < numsSize && nums[index] <= head)
{
head += nums[index++];
}
else
{
head += head;
resultCnt += 1;
}
}
return resultCnt;
}
};
```
### B
```cpp
class Solution
{
public:
int minPatches(vector<int> &nums, int n)
{
int patchCount = 0, i = 0;
long miss = 1;
while (miss <= n)
{
if (i < nums.size() && miss >= nums[i])
miss += nums[i++];
else
{
patchCount++;
miss = miss * 2;
}
}
return patchCount;
}
};
```
### C
```cpp
class Solution
{
public:
int minPatches(vector<int> &nums, int n)
{
int len = nums.size(), i = 0;
long current_coverage = 0;
int ans = 0;
while (current_coverage < n)
{
if (i < len)
{
if (nums[i] <= current_coverage + 1)
{
current_coverage += nums[i];
i++;
}
else
{
ans++;
current_coverage += current_coverage + 1;
}
}
else
{
ans++;
current_coverage += current_coverage + 1;
}
}
return ans;
}
};
```
{
"node_id": "algorithm-79927151f5264497aa7cf4054ca7c573",
"keywords": [
"leetcode",
"最大数"
],
"children": [],
"export": [
"solution.json"
],
"title": "最大数"
}
\ No newline at end of file
<p>给定一组非负整数 <code>nums</code>,重新排列每个数的顺序(每个数不可拆分)使之组成一个最大的整数。</p>
<p><strong>注意:</strong>输出结果可能非常大,所以你需要返回一个字符串而不是整数。</p>
<p> </p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入<code></code></strong><code>nums = [10,2]</code>
<strong>输出:</strong><code>"210"</code></pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入<code></code></strong><code>nums = [3,30,34,5,9]</code>
<strong>输出:</strong><code>"9534330"</code>
</pre>
<p><strong>示例 3:</strong></p>
<pre>
<strong>输入<code></code></strong>nums = [1]
<strong>输出:</strong>"1"
</pre>
<p><strong>示例 4:</strong></p>
<pre>
<strong>输入<code></code></strong>nums = [10]
<strong>输出:</strong>"10"
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= nums.length <= 100</code></li>
<li><code>0 <= nums[i] <= 10<sup>9</sup></code></li>
</ul>
class Solution
{
public:
bool static cmp(string a, string b)
{
return (a + b) > (b + a); //当a+b>b+a时a排在b前面
}
string largestNumber(vector<int> &nums)
{
int flag = 0;
vector<string> v;
for (vector<int>::iterator i = nums.begin(); i < nums.end(); i++)
{
v.push_back(to_string(*i));
if (*i)
flag = 1;
}
if (!flag)
return "0";
sort(v.begin(), v.end(), cmp); //没有生成实例就要调用,故cmp应声明为static
string s = "";
for (int i = 0; i < v.size(); i++)
s = s + v[i];
return s;
}
};
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8ffe9f362cee4808887feae6a1a4baab"
}
\ No newline at end of file
# 最大数
<p>给定一组非负整数 <code>nums</code>,重新排列每个数的顺序(每个数不可拆分)使之组成一个最大的整数。</p>
<p><strong>注意:</strong>输出结果可能非常大,所以你需要返回一个字符串而不是整数。</p>
<p> </p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入<code></code></strong><code>nums = [10,2]</code>
<strong>输出:</strong><code>"210"</code></pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入<code></code></strong><code>nums = [3,30,34,5,9]</code>
<strong>输出:</strong><code>"9534330"</code>
</pre>
<p><strong>示例 3:</strong></p>
<pre>
<strong>输入<code></code></strong>nums = [1]
<strong>输出:</strong>"1"
</pre>
<p><strong>示例 4:</strong></p>
<pre>
<strong>输入<code></code></strong>nums = [10]
<strong>输出:</strong>"10"
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= nums.length <= 100</code></li>
<li><code>0 <= nums[i] <= 10<sup>9</sup></code></li>
</ul>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
Solution sol;
vector<int> nums = {3, 30, 34, 5, 9};
string res = sol.largestNumber(nums);
cout << res;
return 0;
}
```
## 答案
```cpp
class Solution
{
public:
string largestNumber(vector<int> &nums)
{
string ans;
for (int i = 0; i < nums.size(); i++)
{
for (int j = nums.size() - 1; j > i; j--)
{
if (to_string(nums[j - 1]) + to_string(nums[j]) > to_string(nums[j]) + to_string(nums[j - 1]))
{
int tmp = nums[j - 1];
nums[j - 1] = nums[j];
nums[j] = tmp;
}
}
ans += to_string(nums[i]);
}
if (ans + "0" == "0" + ans)
return "0";
return ans;
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
string largestNumber(vector<int> &nums)
{
string ans;
sort(nums.begin(), nums.end(), [](int a, int b)
{ return to_string(a) + to_string(b) > to_string(b) + to_string(a); });
for (auto it : nums)
{
ans += to_string(it);
}
return ans[0] == '0' ? "0" : ans;
}
};
```
### B
```cpp
class Solution
{
public:
string largestNumber(vector<int> &nums)
{
if (*max_element(nums.begin(), nums.end()) == 0)
return to_string(0);
vector<string> vec(nums.size());
for (int i = 0; i < nums.size(); ++i)
vec[i] = to_string(nums[i]);
sort(vec.begin(), vec.end(), [](const string &s1, const string &s2)
{ return s1 + s2 > s2 + s1; });
return accumulate(vec.begin(), vec.end(), string());
}
};
```
### C
```cpp
class Solution
{
public:
string largestNumber(vector<int> &nums)
{
string res = "";
int n = nums.size();
vector<string> tmp;
for (int i = 0; i < n; i++)
{
tmp.push_back(to_string(nums[i]));
}
sort(tmp.begin(), tmp.end(), compare);
for (int i = 0; i < tmp.size(); i++)
{
res += tmp[i];
}
if ('0' == res[0])
{
return "0";
}
else
{
return res;
}
}
};
```
{
"node_id": "algorithm-b19a2b60d98244eb9e56813921864871",
"keywords": [
"leetcode",
"去除重复字母"
],
"children": [],
"export": [
"solution.json"
],
"title": "去除重复字母"
}
\ No newline at end of file
<p>给你一个字符串 <code>s</code> ,请你去除字符串中重复的字母,使得每个字母只出现一次。需保证 <strong>返回结果的字典序最小</strong>(要求不能打乱其他字符的相对位置)。</p>
<p><strong>注意:</strong>该题与 1081 <a href="https://leetcode-cn.com/problems/smallest-subsequence-of-distinct-characters">https://leetcode-cn.com/problems/smallest-subsequence-of-distinct-characters</a> 相同</p>
<p> </p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong><code>s = "bcabc"</code>
<strong>输出<code></code></strong><code>"abc"</code>
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong><code>s = "cbacdcbc"</code>
<strong>输出:</strong><code>"acdb"</code></pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= s.length <= 10<sup>4</sup></code></li>
<li><code>s</code> 由小写英文字母组成</li>
</ul>
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "17a3169f78f74c65ae53df020a642995"
}
\ No newline at end of file
# 去除重复字母
<p>给你一个字符串 <code>s</code> ,请你去除字符串中重复的字母,使得每个字母只出现一次。需保证 <strong>返回结果的字典序最小</strong>(要求不能打乱其他字符的相对位置)。</p>
<p><strong>注意:</strong>该题与 1081 <a href="https://leetcode-cn.com/problems/smallest-subsequence-of-distinct-characters">https://leetcode-cn.com/problems/smallest-subsequence-of-distinct-characters</a> 相同</p>
<p> </p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong><code>s = "bcabc"</code>
<strong>输出<code></code></strong><code>"abc"</code>
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong><code>s = "cbacdcbc"</code>
<strong>输出:</strong><code>"acdb"</code></pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= s.length <= 10<sup>4</sup></code></li>
<li><code>s</code> 由小写英文字母组成</li>
</ul>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
Solution sol;
string s = "cbacdcbc";
string res = sol.removeDuplicateLetters(s);
cout << res;
return 0;
}
```
## 答案
```cpp
class Solution
{
public:
string removeDuplicateLetters(string s)
{
int count[26] = {0};
for (int i = 0; i < s.length(); i++)
count[s[i] - 'a']++;
int pos = 0;
for (int i = 0; i < s.length(); i++)
{
if (s[i] < s[pos])
pos = i;
if (count[s[i] - 'a'] == 0)
break;
}
string suffix;
if (pos + 1 > s.length())
suffix = "";
else
suffix = s.substr(pos + 1, s.length() - pos - 1);
return s.length() == 0 ? "" : s[pos] + removeDuplicateLetters(removeOneLetter(suffix, s[pos]));
}
string removeOneLetter(string s, char ch)
{
while (1)
{
int index = s.find(ch);
if (index != -1)
s = s.erase(index, 1);
else
break;
}
return s;
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
string removeDuplicateLetters(string s)
{
unordered_map<char, int> mp;
unordered_map<char, bool> isIn;
int len = s.length();
for (int i = 0; i < len; i++)
{
mp[s[i]]++;
isIn[s[i]] = false;
}
stack<char> ans;
for (int i = 0; i < len; i++)
{
if (ans.empty())
{
ans.push(s[i]);
isIn[s[i]] = true;
}
else if (!isIn[s[i]])
{
while (!ans.empty() && s[i] < ans.top())
{
if (mp[ans.top()])
{
isIn[ans.top()] = false;
ans.pop();
}
else
break;
}
ans.push(s[i]);
isIn[s[i]] = true;
}
mp[s[i]]--;
}
string ansS;
while (!ans.empty())
{
ansS += ans.top();
ans.pop();
}
reverse(ansS.begin(), ansS.end());
return ansS;
}
};
```
### B
```cpp
class Solution
{
public:
string removeDuplicateLetters(string s)
{
string ans;
for (int i = 0; i < s.size(); i++)
{
if (ans.find(s[i]) != string::npos)
continue;
for (int j = ans.length() - 1; j >= 0; j--)
{
if (ans[j] > s[i] && s.find(ans[j], i + 1) != string::npos)
{
ans.erase(j);
continue;
}
break;
}
ans += s[i];
}
return ans;
}
};
```
### C
```cpp
class Solution
{
public:
string res = "0";
string removeDuplicateLetters(string s)
{
int count[26] = {0};
int visited[26] = {0};
for (int i = 0; i < s.size(); ++i)
++count[s[i] - 'a'];
for (const auto &c : s)
{
--count[c - 'a'];
if (visited[c - 'a'] == 1)
continue;
while (c < res.back() && count[res.back() - 'a'])
{
visited[res.back() - 'a'] = 0;
res.pop_back();
}
res += c;
visited[c - 'a'] = 1;
}
return res.substr(1);
}
};
```
{
"node_id": "algorithm-476b83ac859c40f3a6efd6c3632f1ad2",
"keywords": [
"leetcode",
"拼接最大数"
],
"children": [],
"export": [
"solution.json"
],
"title": "拼接最大数"
}
\ No newline at end of file
<p>给定长度分别为&nbsp;<code>m</code>&nbsp;&nbsp;<code>n</code>&nbsp;的两个数组,其元素由&nbsp;<code>0-9</code>&nbsp;构成,表示两个自然数各位上的数字。现在从这两个数组中选出 <code>k (k &lt;= m + n)</code>&nbsp;个数字拼接成一个新的数,要求从同一个数组中取出的数字保持其在原数组中的相对顺序。</p>
<p>求满足该条件的最大数。结果返回一个表示该最大数的长度为&nbsp;<code>k</code>&nbsp;的数组。</p>
<p><strong>说明: </strong>请尽可能地优化你算法的时间和空间复杂度。</p>
<p><strong>示例&nbsp;1:</strong></p>
<pre><strong>输入:</strong>
nums1 = <code>[3, 4, 6, 5]</code>
nums2 = <code>[9, 1, 2, 5, 8, 3]</code>
k = <code>5</code>
<strong>输出:</strong>
<code>[9, 8, 6, 5, 3]</code></pre>
<p><strong>示例 2:</strong></p>
<pre><strong>输入:</strong>
nums1 = <code>[6, 7]</code>
nums2 = <code>[6, 0, 4]</code>
k = <code>5</code>
<strong>输出:</strong>
<code>[6, 7, 6, 0, 4]</code></pre>
<p><strong>示例 3:</strong></p>
<pre><strong>输入:</strong>
nums1 = <code>[3, 9]</code>
nums2 = <code>[8, 9]</code>
k = <code>3</code>
<strong>输出:</strong>
<code>[9, 8, 9]</code></pre>
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d4bef81d1bd84c0db36d6488b1932479"
}
\ No newline at end of file
# 拼接最大数
<p>给定长度分别为&nbsp;<code>m</code>&nbsp;&nbsp;<code>n</code>&nbsp;的两个数组,其元素由&nbsp;<code>0-9</code>&nbsp;构成,表示两个自然数各位上的数字。现在从这两个数组中选出 <code>k (k &lt;= m + n)</code>&nbsp;个数字拼接成一个新的数,要求从同一个数组中取出的数字保持其在原数组中的相对顺序。</p>
<p>求满足该条件的最大数。结果返回一个表示该最大数的长度为&nbsp;<code>k</code>&nbsp;的数组。</p>
<p><strong>说明: </strong>请尽可能地优化你算法的时间和空间复杂度。</p>
<p><strong>示例&nbsp;1:</strong></p>
<pre><strong>输入:</strong>
nums1 = <code>[3, 4, 6, 5]</code>
nums2 = <code>[9, 1, 2, 5, 8, 3]</code>
k = <code>5</code>
<strong>输出:</strong>
<code>[9, 8, 6, 5, 3]</code></pre>
<p><strong>示例 2:</strong></p>
<pre><strong>输入:</strong>
nums1 = <code>[6, 7]</code>
nums2 = <code>[6, 0, 4]</code>
k = <code>5</code>
<strong>输出:</strong>
<code>[6, 7, 6, 0, 4]</code></pre>
<p><strong>示例 3:</strong></p>
<pre><strong>输入:</strong>
nums1 = <code>[3, 9]</code>
nums2 = <code>[8, 9]</code>
k = <code>3</code>
<strong>输出:</strong>
<code>[9, 8, 9]</code></pre>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
Solution sol;
vector<int> nums1 = {3, 4, 6, 5};
vector<int> nums2 = {9, 1, 2, 5, 8, 3};
int k = 5;
vector<int> res = sol.maxNumber(nums1, nums2, k);
for (auto i : res)
cout << i << " ";
return 0;
}
```
## 答案
```cpp
class Solution
{
public:
struct node
{
int val;
int vec;
int pos;
};
static bool cmp(node a, node b)
{
return a.val > b.val;
}
vector<int> maxNumber(vector<int> &nums1, vector<int> &nums2, int k)
{
int n = nums1.size();
int m = nums2.size();
struct node all[m + n];
vector<int> ans;
for (int i = 0; i < n; i++)
{
all[i].vec = 1;
all[i].val = nums1[i];
all[i].pos = i;
}
for (int i = 0; i < m; i++)
{
all[i + n].vec = 2;
all[i + n].val = nums2[i];
all[i + n].pos = i;
}
sort(all, all + m + n, cmp);
int now1 = 0;
int now2 = 0;
int st = 0;
while (st != n + 1)
{
for (int i = 0; i < n + m; i++)
{
if (all[i].pos >= now1 && n - all[i].pos + m - now2 >= k - st)
{
ans.push_back(all[i].val);
now1 = all[i].pos + 1;
st++;
break;
}
}
}
return ans;
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
vector<int> getNumsFromVector(vector<int> &nums, int k)
{
int n = nums.size();
if (n == 0)
return {};
vector<int> stack;
stack.push_back(nums[0]);
for (int i = 1; i < n; ++i)
{
while (!stack.empty() && nums[i] > stack.back() && (n - i > k - (int)stack.size()))
{
stack.pop_back();
}
stack.push_back(nums[i]);
}
if (stack.size() > k)
{
vector<int> res(stack.begin(), stack.begin() + k);
return res;
}
return stack;
}
int maxNumsVector(vector<int> &nums1, int index1, vector<int> &nums2, int index2)
{
int m = nums1.size(), n = nums2.size();
if (m == 0)
return 2;
if (n == 0)
return 1;
int p1 = index1, p2 = index2;
for (; p1 < m && p2 < n; ++p1, ++p2)
{
if (nums1[p1] < nums2[p2])
{
return 2;
}
if (nums1[p1] > nums2[p2])
{
return 1;
}
}
if (p1 < m)
{
return 1;
}
else
{
return 2;
}
}
vector<int> merge(vector<int> &nums1, vector<int> &nums2)
{
int m = nums1.size(), n = nums2.size();
if (m == 0)
return nums2;
if (n == 0)
return nums1;
vector<int> res(m + n, 0);
int p1 = 0, p2 = 0;
int i = 0;
while (p1 < m && p2 < n)
{
if (nums1[p1] < nums2[p2])
{
res[i++] = nums2[p2++];
}
else if (nums1[p1] == nums2[p2])
{
if (maxNumsVector(nums1, p1, nums2, p2) == 1)
{
res[i++] = nums1[p1++];
}
else
{
res[i++] = nums2[p2++];
}
}
else
{
res[i++] = nums1[p1++];
}
}
while (p1 < m)
{
res[i++] = nums1[p1++];
}
while (p2 < n)
{
res[i++] = nums2[p2++];
}
return res;
}
vector<int> maxNumber(vector<int> &nums1, vector<int> &nums2, int k)
{
int m = nums1.size();
int n = nums2.size();
int begin = max(0, k - n), end = min(k, m);
vector<int> ansNums(k, 0);
for (int i = begin; i <= end; ++i)
{
vector<int> tempNums1 = getNumsFromVector(nums1, i);
vector<int> tempNums2 = getNumsFromVector(nums2, k - i);
vector<int> mergeRes = merge(tempNums1, tempNums2);
if (maxNumsVector(ansNums, 0, mergeRes, 0) == 2)
{
ansNums = mergeRes;
}
}
return ansNums;
}
};
```
### B
```cpp
class Solution
{
public:
vector<int> find_kMax(vector<int> &num, int k)
{
vector<int> res;
int i = 0;
while (k > 0)
{
int idx = i;
for (; i < num.size() - k + 1; ++i)
{
if (num[i] > num[idx])
idx = i;
}
res.push_back(num[idx]);
i = idx + 1;
--k;
}
return res;
}
vector<int> merge(vector<int> &nums1, vector<int> &nums2)
{
vector<int> res;
for (auto iter1 = nums1.begin(), iter2 = nums2.begin(); iter1 != nums1.end() || iter2 != nums2.end();)
{
if (lexicographical_compare(iter1, nums1.end(), iter2, nums2.end()))
res.push_back(*iter2++);
else
res.push_back(*iter1++);
}
return res;
}
vector<int> maxNumber(vector<int> &nums1, vector<int> &nums2, int k)
{
vector<int> res;
for (int i = 0; i <= k; ++i)
{
int j = k - i;
if (i > nums1.size() || j > nums2.size())
continue;
auto tmp1 = find_kMax(nums1, i);
auto tmp2 = find_kMax(nums2, j);
res = max(res, merge(tmp1, tmp2));
}
return res;
}
};
```
### C
```cpp
class Solution
{
public:
vector<int> maxNumber(vector<int> &nums1, vector<int> &nums2, int k)
{
int m = nums1.size(), n = nums2.size();
vector<int> res;
for (int i = max(0, k - n); i <= min(k, m); i++)
res = max(res, mergeVector(maxVector(nums1, i), maxVector(nums2, k - i)));
return res;
}
vector<int> maxVector(vector<int> nums, int k)
{
int drop = nums.size() - k;
vector<int> res;
for (int num : nums)
{
while (drop && res.size() && res.back() < num)
{
res.pop_back();
--drop;
}
res.push_back(num);
}
res.resize(k);
return res;
}
vector<int> mergeVector(vector<int> nums1, vector<int> nums2)
{
vector<int> res;
while (nums1.size() + nums2.size())
{
vector<int> &tmp = nums1 > nums2 ? nums1 : nums2;
res.push_back(tmp[0]);
tmp.erase(tmp.begin());
}
return res;
}
};
```
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c5fd58daecf5409e85df121fe9e7110b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "30dc3fe246f543ec9f26f44b0051cab1"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7026e2bc9ba945ecb75693f21ee96a59"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c768955a81964a16af533b1180acea75"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9fd7021efe434546947e98c9df345ff4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2d7778e134004e3488e6750325998ea7"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c2ed088169324224808baa01bbf3ead3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "609341761cd74b8485fe88a08430b237"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "05818cc221d4482e8312716a8e64ab0e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "02026ccbe5a949de8e9919d285864050"
}
\ No newline at end of file
# 对称二叉树
<p>给定一个二叉树,检查它是否是镜像对称的。</p>
<p>&nbsp;</p>
......@@ -30,10 +31,22 @@
<p>你可以运用递归和迭代两种方法解决这个问题吗?</p>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
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
......@@ -42,21 +55,110 @@
## 答案
```cpp
class Solution
{
public:
bool isSymmetric(TreeNode *root)
{
if (!root)
return true;
queue<TreeNode *> q;
q.push(root->left);
q.push(root->right);
while (!q.empty())
{
auto p1 = q.front();
q.pop();
auto p2 = q.front();
q.pop();
if (!p1 && !p2)
continue;
if (!p1 || !p2)
return false;
if (p1->val != p2->val)
return false;
q.push(p1->right);
q.push(p1->left);
q.push(p2->right);
q.push(p2->left);
}
return true;
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
bool isSymmetric(TreeNode *root)
{
queue<TreeNode *> q1, q2;
if (!root)
return true;
q1.push(root->left);
q2.push(root->right);
while (!q1.empty() && !q2.empty())
{
TreeNode *node1 = q1.front();
q1.pop();
TreeNode *node2 = q2.front();
q2.pop();
if (!node1 && !node2)
continue;
if ((!node1 && node2) || (node1 && !node2) || (node1->val != node2->val))
return false;
q1.push(node1->left);
q1.push(node1->right);
q2.push(node2->right);
q2.push(node2->left);
}
return true;
}
};
```
### B
```cpp
class Solution
{
public:
bool isSymmetric(TreeNode *root)
{
if (!root)
return true;
return helper(root->left, root->right);
}
bool helper(TreeNode *left, TreeNode *right)
{
if (!left && !right)
return true;
if ((!left && right) || (left && !right) || (left->val != right->val))
return false;
return helper(left->left, right->right) && helper(left->right, right->left);
}
};
```
### C
```cpp
class Solution
{
public:
bool isSymmetric(TreeNode *root)
{
return ismirror(root, root);
}
bool ismirror(TreeNode *t1, TreeNode *t2)
{
if (t1 == NULL && t2 == NULL)
return true;
if (t1 == NULL || t2 == NULL)
return false;
return (t1->val == t2->val) && ismirror(t1->left, t2->right) && ismirror(t1->right, t2->left);
}
};
```
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "aae782a36ce34852a0c7e3c73191a549"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "925fa09a52a44aabbbccf6e83911bf46"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "fe1341408a504f5daae4ebf14ae299f6"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9bd9496e3de44835b70e152f2120d974"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6f8984c5ec194d4bb961c5e9e12c5ffd"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "30b0b6f6226d4abcaa84b6c406768769"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "fb1e6aeafb0744928925929af214b4db"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0aefe9665b4243c086f30c8f1b0c1d35"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "21c3b557b87e46899b0e52caaf2b6894"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7aaf537ab5b44771a2c4bbc8d2cf6526"
}
\ No newline at end of file
# 二叉树的层序遍历
<p>给你一个二叉树,请你返回其按 <strong>层序遍历</strong> 得到的节点值。 (即逐层地,从左到右访问所有节点)。</p>
<p> </p>
......@@ -25,10 +26,22 @@
</pre>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
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
......@@ -37,21 +50,147 @@
## 答案
```cpp
class Solution
{
public:
vector<vector<int>> levelOrder(TreeNode *root)
{
vector<vector<int>> res;
queue<TreeNode *> q;
if (root != NULL)
{
while (!q.empty())
{
int size = q.size();
vector<int> temp;
for (int i = 0; i < size; i++)
{
TreeNode *t = q.front();
q.pop();
temp.push_back(t->val);
if (t->left != NULL)
q.push(t->left);
if (t->right != NULL)
q.push(t->right);
}
res.push_back(temp);
temp.clear();
}
}
return res;
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
vector<vector<int>> levelOrder(TreeNode *root)
{
vector<vector<int>> ret;
if (!root)
return ret;
queue<TreeNode *> q;
q.push(root);
while (!q.empty())
{
int currNodeSize = q.size();
ret.push_back(vector<int>());
for (int i = 1; i <= currNodeSize; i++)
{
TreeNode *node = q.front();
q.pop();
ret.back().push_back(node->val);
if (node->left)
q.push(node->left);
if (node->right)
q.push(node->right);
}
}
return ret;
}
};
```
### B
```cpp
class Solution
{
public:
int depth(TreeNode *root)
{
if (root == NULL)
return 0;
return max(depth(root->left), depth(root->right)) + 1;
}
void levelOrder(vector<vector<int>> &ans, TreeNode *node, int level)
{
if (!node)
return;
ans[level].push_back(node->val);
levelOrder(ans, node->left, level - 1);
levelOrder(ans, node->right, level - 1);
}
vector<vector<int>> levelOrderBottom(TreeNode *root)
{
int d = depth(root);
vector<vector<int>> ans(d, vector<int>{});
levelOrder(ans, root, d - 1);
return ans;
}
};
```
### C
```cpp
class Solution
{
public:
void dfs(TreeNode *root, vector<vector<int>> &res)
{
queue<TreeNode *> q;
q.push(root);
while (!q.empty())
{
int sz = q.size();
vector<int> tp;
while (sz > 0)
{
TreeNode *p = q.front();
q.pop();
if (p->left != NULL)
{
q.push(p->left);
}
if (p->right != NULL)
{
q.push(p->right);
}
tp.push_back(p->val);
sz--;
}
res.push_back(tp);
}
}
vector<vector<int>> levelOrder(TreeNode *root)
{
vector<vector<int>> res;
if (root == NULL)
{
return res;
}
dfs(root, res);
return res;
}
};
```
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "783b99867b01438786d8e908915e3868"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6582648f7f4b428eabc19c160a6b105c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c941327100fd4953ad6b7d7c0632058b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ab58c78a3fb94f319eed0c643df90b47"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c30595a58fbb49088e3fb12fefa5cc29"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "275efc18bde0410293debbb6ca73ea7b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6fd97bfd6e3f49659559ebe411a5b73d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "74552887a9ea4d239dc0fc1e43eddf30"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e5a7631e14234838a6e00c656242a134"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "eb464e5a900d40b6a3ec8e6b24511665"
}
\ No newline at end of file
# 二叉树的锯齿形层序遍历
<p>给定一个二叉树,返回其节点值的锯齿形层序遍历。(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行)。</p>
<p>例如:<br />
......@@ -23,10 +24,22 @@
</pre>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
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
......@@ -35,21 +48,232 @@
## 答案
```cpp
class Solution
{
public:
vector<vector<int>> zigzagLevelOrder(TreeNode *root)
{
vector<vector<int>> result;
if (root == NULL)
{
return result;
}
deque<TreeNode *> node_queue;
node_queue.push_back(root);
node_queue.push_back(NULL);
deque<int> level_list;
bool is_order_left = true;
while (node_queue.size() > 0)
{
TreeNode *curr_node = node_queue.front();
node_queue.pop_front();
if (curr_node != NULL)
{
if (curr_node->left != NULL)
{
node_queue.push_back(curr_node->left);
}
if (curr_node->right != NULL)
{
node_queue.push_back(curr_node->right);
}
}
else
{
vector<int> tmp;
for (int a : level_list)
{
tmp.push_back(a);
}
result.push_back(tmp);
level_list.clear();
if (node_queue.size() > 0)
{
node_queue.push_back(NULL);
}
is_order_left = !is_order_left;
}
}
return result;
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
vector<vector<int>> zigzagLevelOrder(TreeNode *root)
{
if (root == NULL)
return {};
vector<vector<int>> res;
int flag = 1;
stack<TreeNode *> a, b;
a.push(root);
while (!a.empty() || !b.empty())
{
vector<int> cur;
while (flag == 1 && !a.empty())
{
root = a.top();
cur.push_back(root->val);
a.pop();
if (root->left != NULL)
b.push(root->left);
if (root->right != NULL)
b.push(root->right);
}
while (flag == -1 && !b.empty())
{
root = b.top();
cur.push_back(root->val);
b.pop();
if (root->right != NULL)
a.push(root->right);
if (root->left != NULL)
a.push(root->left);
}
flag = -1 * flag;
res.push_back(cur);
}
return res;
}
};
```
### B
```cpp
class Solution
{
public:
vector<vector<int>> zigzagLevelOrder(TreeNode *root)
{
vector<vector<int>> ans;
if (!root)
return ans;
queue<TreeNode *> qnode;
bool orderByLeft = true;
qnode.push(root);
while (!qnode.empty())
{
int levelSize = qnode.size();
deque<int> level;
for (int i = 0; i < levelSize; i++)
{
auto curNode = qnode.front();
qnode.pop();
if (orderByLeft)
{
level.push_back(curNode->val);
}
else
{
level.push_front(curNode->val);
}
if (curNode->left != NULL)
qnode.push(curNode->left);
if (curNode->right != NULL)
qnode.push(curNode->right);
}
orderByLeft = !orderByLeft;
vector<int> curlevel{level.begin(), level.end()};
ans.push_back(curlevel);
}
return ans;
}
};
```
### C
```cpp
class Solution
{
public:
vector<vector<int>> zigzagLevelOrder(TreeNode *root)
{
if (!root)
return {};
vector<vector<int>> res;
queue<TreeNode *> q{{root}};
int cnt = 0;
while (!q.empty())
{
vector<int> oneLevel;
for (int i = q.size(); i > 0; i--)
{
TreeNode *t = q.front();
q.pop();
oneLevel.push_back(t->val);
if (t->left)
q.push(t->left);
if (t->right)
q.push(t->right);
}
if (cnt % 2 == 1)
reverse(oneLevel.begin(), oneLevel.end());
res.push_back(oneLevel);
cnt++;
}
return res;
}
};
```
### D
```cpp
class Solution
{
public:
vector<vector<int>> zigzagLevelOrder(TreeNode *root)
{
vector<vector<int>> results;
if (root == NULL)
{
return results;
}
zigzagLevelOrderDFS_helper(root, 0, results);
return results;
}
void zigzagLevelOrderDFS_helper(TreeNode *node, int level, vector<vector<int>> &results)
{
if (level >= results.size())
{
vector<int> new_level;
new_level.push_back(node->val);
results.push_back(new_level);
}
else
{
if (level % 2 == 0)
{
results[level].push_back(node->val);
}
else
{
results[level].insert(results[level].begin(), node->val);
}
}
if (node->left != NULL)
{
zigzagLevelOrderDFS_helper(node->left, level + 1, results);
}
if (node->right != NULL)
{
zigzagLevelOrderDFS_helper(node->right, level + 1, results);
}
}
};
```
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d1fa694ebe224546bcf4ce6d013eda9b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e13470b44c6347608e24ab44ad4d87aa"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "fe5793ab8cb8475a90ed10f540ec1a52"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2b36f3ad745d486c9e60e9bc2e42e8f9"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b184f3ab93b64a12ad574dbe60698365"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "bd8ea3e19f1747a89664be42038106ab"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e2e9ce6adfaa4999a1c5367e08afcd41"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "340f4daaa0b84744b3d4d636df2f5682"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ca03c43d8b374e198a49f93cf81967c9"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5b98eb17e0614a178005e60fc8fe617b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ba6835189650408cb8e0479534e5a547"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c5a0d30cc9674434941daca990769ff3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1cba435344df49d59a79fac41716a679"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "dfbbeec8e30c4ca5b6035555f4ef5574"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "39b492b39f8f48858aa4f6a129880451"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b0b32e57ed734267bb83ad1712e110c6"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0df99d4d4ce644c2963574cd81fdd594"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5def1648634044689aa910cafac01a69"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0743aeeec99f4357b91ca434bf77f6c3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6b4af7eec3bc4c42affd56b73252f509"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "bb1c678d8c7a4551bfed0cc542a92e18"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "03c6d67f12eb42f3bff8ad0571aae8d9"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "dd947ef3eaeb457fa3e1b63cbfb1cad8"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "34d07a6de6764707a263b1bc8d29d46c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1d4d31bc5001477fa7dd9e715a6c5d7b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b6d9c2e161254dc0972fac3453394cd3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "4e3fda59b2d6465b8fe17a9048b451ab"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "86a7c6e0e8ae41d19693efcd4a65ec8a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f94276d46e434c19bce4867f30c062cc"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "afb08b37eead483d9e578a89a84f99f8"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c7f6ad3fafb8405485cfc6061b0b0f37"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "026ef0e92905403b849a9e6a33b68dc9"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "19cba7b62c174b7a9d17ea7c59d0a7ed"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "827a0fbe0c254e91a049928c58a725b0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c40c1b0bbc2a4765a0999893fb2ee2a7"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d9abb8c04087441d831994c15ef9ba1c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "97072337f0cf4ed3b9e817f446b8a8cc"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "232ad8d95166413f9de1e49d5ce4d002"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "758d01536ff54b0d9a1c03b0a6141370"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "fcfd2314af624ce7a2d1dc1cb3f610ab"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8d59fb584aec4908a40314555ab95f3d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "dac7d5c5458d453cbe3f37bf40715241"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e0105a84d7ff4bae8810706c331b4643"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d915deffaa8d4b6fabacd3b80bedd610"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8681c9959ba34bd89aca952152f21aa1"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7c27841f08934fc4bcf00d9a74eb4bd6"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3d16dc25849e499c87d3d5fad1f7b480"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f4a4d7aa21414ac6adccd58c0d942f96"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "50aae6938abb4dd78d9b73bc3c9618e8"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "63c7024e5140404e836536b06c65421f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2b08e5c18b69455c950b3dcca8ddabc2"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6cb546709aec41b7b32423fbca1f0291"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b104f0b4f1914375ac0759ce49c1eecd"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0a369dd9fcf94f5eb06115ea8aece935"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5be03627c75941188f2598ec869db85b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "af00556a7f524d5ba262f4b91cf9cce1"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "bd5b809c9a8e40748bd23b0f1fd10c76"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "98011ee1bdbc41f5b6e2f7d620044017"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "863459d852474841a9c0de26b32bcaf2"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6fca1fb76410492e8edabb2ed7046ec3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5630532f4740471e8ffb4ab0cddc1f0f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3c452cf552244782a25c2beb92a88bf7"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e3eb682d58394a908e4950a5b8aa4e6b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2f32b7313db24b9987158ad6c3130bff"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b32725a638314d83af74cd5be7aedc97"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3e6a23bbf9bb4f2bab918347c8c2a708"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c0a0aa133ccf4fffac6d5a996218f44e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "51635c2cce11474e98d92926103dadba"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "979c100ccab646b1b2f3d69053aa4f09"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "203421fc2640456483be7b4d401b015f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "847f39d957cb453581e3a97c31211b7f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1da26f6666784ee18b645038bcda0c41"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "35578c946cd54360a33e07eef28895f7"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ec34b01121b2463ebb648f647f6d062e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "cf6fe090237247ce95e7dede7106467f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6ae7cf591ee94960abb05e1c1f66d219"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5f5c2ffafdbf4406a9d6f6b624247445"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "24707b7591924930874ca286a3be8e37"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6bc7dee34c624a93a7a9b1a9cb64fecc"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "35343769668c4e31bfe11c649f8f30ed"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "df02e26c0dda4345b586826bcb745127"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "515692181eb54cc3b93ce8c89cc48346"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d8c6e05a7254467fa4b2870844ba108c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6eb2b55b68f0458a9cda5ce69bc80284"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "da090a618af849e9a17b84af65408010"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5c305ff26a86425eb597a170f03d8ce6"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "93a0b9eb8fd048bfbde7fb167751f302"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8cb6fdb90be44a2d871fb2b2d727c69e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "4ef77ebc90494b749a3f20ee1ac2fa40"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5f48d10a400144e4909f80c21d65a215"
}
\ No newline at end of file
......@@ -37,10 +37,22 @@
</ul>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
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
......@@ -49,21 +61,97 @@
## 答案
```cpp
其他三个都是错的
```
## 选项
### A
```cpp
class Solution
{
public:
bool hasPathSum(TreeNode *root, int sum)
{
if (root == NULL)
{
return false;
}
vector<TreeNode *> node_stack;
vector<int> sum_stack;
node_stack.push_back(root);
sum_stack.push_back(sum - root->val);
TreeNode *node;
int curr_sum;
while (!node_stack.empty())
{
node = node_stack.back();
node_stack.pop_back();
curr_sum = sum_stack.back();
sum_stack.pop_back();
if ((node->right == NULL) && (node->left == NULL) && (curr_sum == 0))
{
return true;
}
if (node->right != NULL)
{
node_stack.push_back(node->right);
sum_stack.push_back(curr_sum - node->right->val);
}
if (node->left != NULL)
{
node_stack.push_back(node->left);
sum_stack.push_back(curr_sum - node->left->val);
}
}
return false;
}
};
```
### B
```cpp
class Solution
{
public:
bool hasPathSum(TreeNode *root, int sum)
{
if (root == NULL)
return false;
stack<pair<TreeNode *, int>> s;
s.push(make_pair(root, sum));
TreeNode *node = root;
int currSum;
while (!s.empty())
{
node = s.top().first;
currSum = s.top().second;
s.pop();
if (node->left == NULL && node->right == NULL && node->val == currSum)
return true;
if (node->right)
s.push(make_pair(node->right, currSum - node->val));
if (node->left)
s.push(make_pair(node->left, currSum - node->val));
}
return false;
}
};
```
### C
```cpp
class Solution
{
public:
bool hasPathSum(TreeNode *root, int sum)
{
if (!root)
return false;
if (!root->left && !root->right && root->val == sum)
return true;
return hasPathSum(root->left, sum - root->val) || hasPathSum(root->right, sum - root->val);
}
};
```
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9686849f06194dad92dbab60aa2cee1a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "243e74999353408a9ec3e8b503d20732"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "93ec174c3021401db653cd25a9240d4d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d3821c09bf454cfb8cc687e5540cf1e7"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9f06d9767c0345ddac93f7031508a286"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0f37190cde4c4c3fad642d36c04c1e5c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "634cb9e4787a4f1ba9b4c208ce0dd3d7"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d2849892ea524bd9b1df3a99548298ce"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "eb5f0c973a0e4e9d98d16044625d1527"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6eed9e45a2bf4bcf9b2fbb6edb66693a"
}
\ No newline at end of file
......@@ -41,9 +41,22 @@
</div>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
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
......@@ -53,21 +66,131 @@
## 答案
```cpp
class Solution
{
public:
vector<vector<int>> pathSum(TreeNode *root, int sum)
{
int pos = 0;
vector<int> path;
vector<vector<int>> result;
dfs(root, sum, pos, path, result);
return result;
}
private:
void dfs(TreeNode *root, int sum, int &pos, vector<int> &path, vector<vector<int>> &result)
{
if (root == NULL)
return;
pos += root->val;
path.push_back(root->val);
if (!root->left && !root->right && pos == sum)
result.push_back(path);
dfs(root->left, sum, pos, path, result);
dfs(root->right, sum, pos, path, result);
path.pop_back();
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
void find(TreeNode *node, vector<vector<int>> &result, vector<int> &path, int sum)
{
path.push_back(node->val);
if (node->left == NULL && node->right == NULL && sum == node->val)
{
result.push_back(path);
return;
}
if (node->left != NULL)
{
find(node->left, result, path, sum - node->val);
path.pop_back();
}
if (node->right != NULL)
{
find(node->right, result, path, sum - node->val);
path.pop_back();
}
}
vector<vector<int>> pathSum(TreeNode *root, int sum)
{
vector<vector<int>> result;
vector<int> path;
if (root == NULL)
{
return result;
}
find(root, result, path, sum);
return result;
}
};
```
### B
```cpp
class Solution
{
public:
vector<vector<int>> pathSum(TreeNode *root, int sum)
{
vector<vector<int>> res;
if (!root)
return res;
vector<int> temp;
dfs(root, res, temp, sum);
return res;
}
void dfs(TreeNode *root, vector<vector<int>> &res, vector<int> temp, int sum)
{
temp.push_back(root->val);
if (!root->left && !root->right && 0 == sum - root->val)
res.push_back(temp);
if (root->left)
dfs(root->left, res, temp, sum - root->val);
if (root->right)
dfs(root->right, res, temp, sum - root->val);
}
};
```
### C
```cpp
class Solution
{
public:
vector<vector<int>> pathSum(TreeNode *root, int targetSum)
{
DFS(root, targetSum);
return result;
}
void DFS(TreeNode *root, int targetSum)
{
if (root == nullptr)
return;
tmp_path.emplace_back(root->val);
targetSum -= root->val;
if (root->left == nullptr && root->right == nullptr && targetSum == 0)
{
result.emplace_back(tmp_path);
}
DFS(root->left, targetSum);
DFS(root->right, targetSum);
tmp_path.pop_back();
}
private:
vector<vector<int>> result;
vector<int> tmp_path;
};
```
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f011dbf399af44298d68db9908a6e7d8"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5359519347ea449fa95ab62f9cef268c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3b96d201f3704f709d931e813774aba4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "19dee2eaae5244c88559118f5f4b1248"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5c58a0e700ee4b57abde4c2ba8af47e9"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5c54f087a9a04dadb2b6de83c91bc4c8"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "faee8dc60ea441a290be2a74095af09e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8566298757cf435c813e23daa53101d6"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8433469531594e32a9f8a7e32616760e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "54074cebaac349538a07d6d78e32817a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "95d6e30a39bf41c3a1bb69275bd177be"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "07b72b46490f409db9fa750e2d6a9a86"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "30213f5e217344ee9d2b46c15e141908"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "33849e7a24eb4dcfbce167da768afdff"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2c41ec80637a43dc8b5891357445ff79"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "48e38d64746d49da837e856b32d647d7"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "247472b7ff054c948b82fde487b58330"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0cfbf57d17fa41f381bb853b60a326f0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2e403921f11242e4b2a0224af32352ad"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "405a75fd37da44219a53273ed817dc92"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b2b02eca1cb14d92a04b87fecbee44ef"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "34fd0247d84747409efe91556511fa2a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c47bc92718594977b1edf293d9bd9308"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f59a4c21299e4273b676d7528e2dc2db"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "060edf41723e468f8117e156a134d49d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6671ef6d72b14157b8bc65f486e28a78"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "07eeeb7e2662460da0db49f60ca4e67a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "efe074b26e65454ea1b9c60ba374483e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0ae2ea39703944c2ad66aecd283e772a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "11fbb099830b42cb99afafb219c1ee39"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d18ebdafea3046238dd7480a15cebdec"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "50e84bb38ba045a9a19ffa522f6d55d9"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c945e808a17b4ddaabd17f1429b03203"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "4fb9b093eb38451b887c76f9da0c51a2"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "54e9249b281d42aea6cda1a7d1be1ba9"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2c1afc0a9ab84c8499cf23166cce9c9c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "16e31e12fbb54fe483e2fc1f03269841"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9127fa52ecc24adf968e0d02dd8e8fa9"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1a6483e4bd5b447fb0d1d30f724a7959"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e964b22b72dc408db54de7071c298396"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "dd3dde0833c14bbeb3424a2f6398a1bd"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "054d744b589546918cbf154bee15bfec"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1997e913e2c6418e9a1db1ac30a1b3e5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6edb8dfd995b4c0499abafdce7007022"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b2bcf05dde724aecab7c31a782c57625"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1ee88f29f27344fab97229db0d1fff67"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3ff12084254b460c855d0958ec79b942"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b2587e2b18414feab00b056ca2a74074"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "cade99cc8dcd472a8c9b29a57dabb929"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "14aba9b1615947ca80be5e00b74f537e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "608d2f5c7c4a40d78c445ecd77e55d5b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "519a78a30ca6430eaabc3b6095527e22"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "20ae639091b94861befcc177749000de"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2ac9a7f7d3c94efda8674f46976a5e0a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d7fe630e8bda4cb9954c7c2d7d1684d1"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "4f89a176f7bd48b4a2deed8980dcdc4a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "fcd38d1c41284d3381a75c9832c1aa08"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6345b8827cc74226af81a7561bbf5f8c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f4a5a7a1ce1d4f31a339d70e6e9cfbb1"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "4f67834927794d19bb9ef39c30867dd2"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6b2ac675689843aaaeb13a7d9d92e970"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5e7daa6d18e24d458c0f673e3ca0e694"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b72fd54fe9fc44d692c7bee59a62711a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "56adedc4d6b542438d262b11eabe6457"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ecad5b9007114068a94d93b2cc0b2eb4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "76a86bf73f4a40c2830ce11f5a909bd8"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "34b106382bd44926ad27d2543d73586e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8fba69c49c574abd9fa261f9d56cad2f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a770d22a728a44039852db2eeffd05a5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "06058ccfa4e64e4799e00d243735dbfb"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9863ac68f55c420cb566a6377800d126"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0fa7675c4ef743a292d46c2b174fca80"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a1a5f036118948caba107b342628d04e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a7185396da004a7d8ef5972f3b538245"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "98d17dc0c0fe4b77add42a26a8beb493"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7036e514129d4648881ecd512dc2b7d8"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "550d5c7c39d245158035ce3f113c3e92"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0927ef8aaf104147b06351dc08dba45d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c3f2a5e69b4e45d18c54d71b4f753471"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "31cbaedb695044ae8b9cdf481f8bdaed"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "44171d8d837e46438da2ef825d1d9a24"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "75fe4e69beae452ea2b89c7e7f90dca5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8a199cb4f2de4f32b663d2279273929f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9a1b7fffc00a444f917721ee425d5962"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3b80d421714c403590d67011aba92371"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "96fc854db1c84822a125c977cb92f20c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "897a3583152f4e9ebb5c2538e7a5c228"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b79e5d71b7324c21b0f3f17ba95f9cc9"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6b188e5d5c3b4b32bb10b3e762c4c371"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3388a6d4386c47df9ad762a18c4500c2"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b8cbe05ab4704e1880addf18a086041f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0a4b660abfef4583840a1eafd3af7b0a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3bda901286184372ae3944542380659e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b195f55bfc954fe0a97d8da85c1ec5ec"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f97c625ee7974d98bde4a20be287a277"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8e6e472de08e451fbc6de43bad0e3f1d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0e8b4bd6cd32432a98b7b1adda6e747f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "03e879a865b341aea25b0f99fa335f5f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "70c2a3d90789410dbf28ce5667f442a3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "14880c5fe7db402892a7c63e295138e8"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e21335a3900f49a8ae7ef8a40abbf9e3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c63fea8de9534cc6bfd2a08a3468ca56"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c150b2b1151d4315acdceca74ed26f71"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "858d77dcba0c4da09df11287d55cbfe6"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "84971720b5ab4fe786b56b764b36b8e3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5cb7a7d3b1204be1a6b66abbcfc9ad9e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f80908f669504e38b3cce7531b4214f5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a7833dded1654c51a28bbb6404f61e34"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c99bf3623aa94100a46db697dfb8b8ea"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2ce736ca84c048c09e701125bbc5e47c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2bf6d7947e7e44539822918daa2809e5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "be9e60f538c8407db676394baa18c53b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "be5e43d004d14e78a4947f61d4dbd569"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d79fe0a78438468eb232b582e11a574e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b637b9ee199840e498408adb5dca3ece"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8cdf201d51344481a453469ac082b2c7"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5a879ff8bcfc44abb63678d6ce7fb9cd"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5059fcf396ac415fbabed95ab11058c2"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6a1d92c07a854ed5babfd1b0cbf01223"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "59bebd84991c48a2a3fcf14b0158baa0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ff76265c13ae413bb91ac8d9f5486150"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2eb35eaca98b4969bd9edcecb5533a01"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ae40bdd8717e4d06826b35f2e8eb43ba"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "231d4c4d416e4852b4e4b63f49656ab2"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0465a903c9704e329f0d33550a7df1e1"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "812158f6189d41738ff38e2b523de2e4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "522c32f51af9407bb7d3e8a0610be338"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f538d906227543018d37757859b46737"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "cd6a5cdca92a4a54b2142e369a516fd9"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0688cbe5ebee4d899f1c2da1b17b49c9"
}
\ No newline at end of file
# 单词接龙 II
<p>按字典 <code>wordList</code> 完成从单词 <code>beginWord</code> 到单词 <code>endWord</code> 转化,一个表示此过程的 <strong>转换序列</strong> 是形式上像 <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> 这样的单词序列,并满足:</p>
<div class="original__bRMd">
......@@ -48,33 +49,307 @@
</div>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
Solution sol;
vector<vector<string>> res;
string beginWord = "hit", endWord = "cog";
vector<string> wordList = {"hot", "dot", "dog", "lot", "log", "cog"};
res = sol.findLadders(beginWord, endWord, wordList);
for (auto i : res)
{
for (auto j : i)
cout << j << " ";
cout << endl;
}
return 0;
}
```
## 答案
```cpp
class Solution
{
public:
unordered_map<string, vector<string>> tree;
vector<vector<string>> ans;
void dfs(vector<string> &cur, string curWord, string endWord)
{
if (curWord == endWord)
{
ans.push_back(cur);
return;
}
for (string s : tree[curWord])
{
cur.push_back(s);
dfs(cur, s, endWord);
cur.pop_back();
}
}
vector<vector<string>> findLadders(string beginWord, string endWord, vector<string> &wordList)
{
if (wordList.size() == 0 || find(wordList.begin(), wordList.end(), endWord) == wordList.end())
return {};
unordered_set<string> bfsFromBegin{beginWord};
unordered_set<string> bfsFromEnd{endWord};
unordered_set<string> dirc(wordList.begin(), wordList.end());
bool findFlag = false, reverseFlag = false;
while (!bfsFromBegin.empty())
{
unordered_set<string> next;
for (string s : bfsFromBegin)
dirc.erase(s);
for (string s1 : bfsFromBegin)
{
for (int i = 0; i < s1.size(); ++i)
{
string s2 = s1;
for (char c = 'a'; c <= 'z'; ++c)
{
s2[i] = c;
if (dirc.count(s2) == 0)
continue;
next.insert(s2);
}
reverseFlag ? tree[s2].push_back(s1) : tree[s1].push_back(s2);
}
}
bfsFromBegin = next;
if (bfsFromBegin.size() > bfsFromEnd.size())
{
reverseFlag = !reverseFlag;
swap(bfsFromBegin, bfsFromEnd);
}
if (findFlag)
break;
}
vector<string> cur = {beginWord};
dfs(cur, beginWord, endWord);
return ans;
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
bool differ_one(string &s, string &t)
{
int n = 0;
for (int i = 0; i < s.size(); ++i)
if ((n += s[i] != t[i]) > 1)
return false;
return n == 1;
}
vector<vector<int>> fa;
vector<string> tmp;
vector<vector<string>> ans;
void dfs(int index, vector<string> &wordList)
{
if (fa[index].empty())
{
reverse(tmp.begin(), tmp.end());
ans.push_back(tmp);
reverse(tmp.begin(), tmp.end());
}
for (auto &x : fa[index])
{
tmp.push_back(wordList[x]);
dfs(x, wordList);
tmp.pop_back();
}
}
vector<vector<string>> findLadders(string beginWord, string endWord, vector<string> &wordList)
{
int b = -1, e = -1, x;
for (int i = 0; i < wordList.size(); ++i)
{
if (wordList[i] == beginWord)
b = i;
if (wordList[i] == endWord)
e = i;
}
if (e == -1)
return ans;
if (b == -1)
wordList.push_back(beginWord), b = wordList.size() - 1;
queue<int> que;
fa.assign(wordList.size(), vector<int>());
vector<int> index(wordList.size(), 0);
que.push(b), index[b] = 1;
while (!que.empty())
{
x = que.front(), que.pop();
if (index[e] && index[x] >= index[e])
break;
for (int i = 0; i < wordList.size(); ++i)
if ((index[i] == 0 || index[x] + 1 == index[i]) && differ_one(wordList[x], wordList[i]))
if (index[i] == 0)
index[i] = index[x] + 1, que.push(i), fa[i].push_back(x);
else
fa[i].push_back(x);
}
if (index[e] == 0)
return ans;
tmp.push_back(endWord);
dfs(e, wordList);
tmp.pop_back();
return ans;
}
};
```
### B
```cpp
class Solution
{
public:
vector<vector<string>> findLadders(string beginWord, string endWord, vector<string> &wordList)
{
unordered_set<string> list(wordList.begin(), wordList.end());
if (!list.count(endWord))
return {};
unordered_map<string, unordered_set<string>> trace;
unordered_set<string> p;
unordered_set<string> q{beginWord};
while (q.size() && !trace.count(endWord))
{
for (auto w : q)
{
list.erase(w);
}
p.clear();
for (auto str : q)
{
for (int i = 0; i < str.size(); ++i)
{
string tmp = str;
for (char c = 'a'; c <= 'z'; ++c)
{
tmp[i] = c;
if (list.find(tmp) == list.end())
continue;
trace[tmp].insert(str);
p.insert(tmp);
}
}
}
q = p;
}
if (!trace.size())
return {};
vector<vector<string>> res;
dfs(res, {}, trace, endWord);
return res;
}
void dfs(vector<vector<string>> &res, vector<string> path, unordered_map<string, unordered_set<string>> &trace, string &str)
{
path.push_back(str);
if (trace.count(str) == 0)
{
reverse(path.begin(), path.end());
res.push_back(path);
return;
}
for (auto word : trace[str])
dfs(res, path, trace, word);
}
};
```
### C
```cpp
class Solution
{
public:
vector<vector<string>> findLadders(string beginWord, string endWord, vector<string> &wordList)
{
vector<vector<string>> ans;
unordered_set<string> dict(wordList.begin(), wordList.end());
vector<string> p{beginWord};
queue<vector<string>> paths;
paths.push(p);
unordered_set<string> words;
int level = 1, minlength = INT_MAX;
while (!paths.empty())
{
vector<string> t = paths.front();
paths.pop();
if (t.size() > level)
{
for (string s : words)
dict.erase(s);
words.clear();
level = t.size();
if (level > minlength)
break;
}
string last = t.back();
for (int i = 0; i < last.size(); ++i)
{
string newlast = last;
for (char ch = 'a'; ch <= 'z'; ++ch)
{
newlast[i] = ch;
if (!dict.count(newlast))
continue;
words.insert(newlast);
vector<string> nextpath = t;
nextpath.push_back(newlast);
if (newlast == endWord)
{
ans.push_back(nextpath);
minlength = level;
}
else
{
paths.push(nextpath);
}
}
}
}
return ans;
}
};
```
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "29ef3c5a668b457cac60f2c6fb4844de"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "532a0b44a27a422c856ba674fde7ef44"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1b7860a8b6044744b8908086824d9831"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8b62124912b840d9975a8511dc24d6f2"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "91702b08a4eb41de9cb30d0e9d51c696"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "110eaed10a434c6c9193ffbcfd699c33"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "eb94f65ace2c4dc2bb685c77189d2de2"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6f55c26f737c4778a72f1060fe963e88"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2916a42ce72648b6888c09e72c8edf5f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2b980ecd541d4aedaebdf5a8144935e6"
}
\ No newline at end of file
# 单词接龙
<p>字典 <code>wordList</code> 中从单词 <code>beginWord</code><em> </em><code>endWord</code><strong>转换序列 </strong>是一个按下述规格形成的序列:</p>
<ul>
......@@ -41,33 +42,208 @@
</ul>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
Solution sol;
int res;
string beginWord = "hit", endWord = "cog";
vector<string> wordList = {"hot", "dot", "dog", "lot", "log", "cog"};
res = sol.ladderLength(beginWord, endWord, wordList);
cout << res;
return 0;
}
```
## 答案
```cpp
class Solution
{
public:
int ladderLength(string beginWord, string endWord, vector<string> &wordList)
{
unordered_set<string> word;
for (auto s : wordList)
{
word.insert(s);
}
if (word.find(endWord) == word.end())
{
return 0;
}
queue<string> que;
que.push(beginWord);
unordered_set<string> visited;
visited.insert(beginWord);
int num = 1;
while (!que.empty())
{
int m = que.size();
for (int i = 0; i < m; i++)
{
string str = que.front();
que.pop();
if (str == endWord)
{
return num;
}
for (int j = 0; j < str.size(); j++)
{
string ss = str;
for (int k = 0; k < 26; k++)
{
char c = k + 'a';
if (c != str[j])
{
ss[j] = c;
}
if (visited.find(ss) == visited.end())
{
visited.insert(ss);
que.push(ss);
}
}
}
}
num++;
}
return 0;
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
int ladderLength(string beginWord, string endWord, vector<string> &wordList)
{
unordered_set<string> wordSet(wordList.begin(), wordList.end());
if (!wordSet.count(endWord))
return 0;
unordered_map<string, int> pathCount{{{beginWord, 1}}};
queue<string> q{{beginWord}};
while (!q.empty())
{
string word = q.front();
q.pop();
for (int i = 0; i < word.size(); i++)
{
string newWord = word;
for (char c = 'a'; c <= 'z'; c++)
{
newWord[i] = c;
if (wordSet.count(newWord) && newWord == endWord)
return pathCount[word] + 1;
if (wordSet.count(newWord) && !pathCount.count(newWord))
{
pathCount[newWord] = pathCount[word] + 1;
q.push(newWord);
}
}
}
}
return 0;
}
};
```
### B
```cpp
class Solution
{
public:
int ladderLength(string beginWord, string endWord, vector<string> &wordList)
{
queue<string> q;
map<string, int> m1;
map<string, int> re;
int n = wordList.size();
for (int i = 0; i < n; i++)
m1[wordList[i]] = 1;
re[beginWord] = 1;
q.push(beginWord);
while ((!q.empty()) && m1.size())
{
string now = q.front();
q.pop();
int num = re[now];
int llen = now.size();
for (int i = 0; i < llen; i++)
{
string temp = now;
for (char c = 'a'; c <= 'z'; c++)
{
if (temp[i] == c)
continue;
else
temp[i] = c;
if (m1.find(temp) != m1.end())
{
if (temp == endWord)
return num + 1;
q.push(temp);
re[temp] = num + 1;
m1.erase(temp);
}
}
}
}
return 0;
}
};
```
### C
```cpp
class Solution
{
public:
int ladderLength(string beginWord, string endWord, vector<string> &wordList)
{
unordered_set<string> set(wordList.begin(), wordList.end());
if (!set.count(endWord))
return 0;
queue<pair<string, int>> q;
q.push({beginWord, 1});
while (!q.empty())
{
string cur = q.front().first;
int step = q.front().second;
q.pop();
if (cur == endWord)
return step;
for (int i = 0; i < cur.size(); ++i)
{
char ch = cur[i];
for (char c = 'a'; c <= 'z'; ++c)
{
if (c == ch)
continue;
cur[i] = c;
if (set.count(cur))
{
q.push({cur, 1 + step});
set.erase(cur);
}
}
cur[i] = ch;
}
}
return 0;
}
};
```
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0655936f05744347a35896d9cbe4809a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "08f9df5b29604656ae4f47ac37a99596"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d4afd5b7ec75416eab7ec8cc294fb520"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a0804ac80c1246c9b44cbeb6b2564da4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f5315a1af82e49cf975f3f2831c250de"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e2576a710a4240ebb99b5c4942e2c389"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "caacedf5706f4cdd84999233e85715f0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f3af026a6613431fb903713a6b305262"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "292c6821c8cf48d3a4e1bcc40a4954d1"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1eafc7122c374b9087ecb4dfe7cdef6f"
}
\ No newline at end of file
......@@ -29,33 +29,196 @@
</ul>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
Solution sol;
int res;
vector<int> vec = {0, 3, 7, 2, 5, 8, 4, 6, 0, 1};
res = sol.longestSequence(vec);
cout << res;
return 0;
}
```
## 答案
```cpp
class Solution
{
public:
int longestConsecutive(vector<int> &nums)
{
unordered_set<int> hash;
for (const int &num : nums)
{
hash.insert(num);
}
int ans = 0;
while (!hash.empty())
{
int cur = *(hash.begin());
hash.erase(cur);
int next = cur + 1, prev = cur - 1;
while (hash.count(next))
{
hash.erase(next++);
}
while (hash.count(prev))
{
hash.erase(prev--);
}
ans = max(ans, next - prev);
}
return ans;
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
int longestConsecutive(vector<int> &nums)
{
unordered_map<int, int> mp;
int l = 0, r = 0, res = 0, len = 0;
for (int num : nums)
{
if (!mp[num])
{
l = mp[num - 1];
r = mp[num + 1];
len = l + r + 1;
res = max(res, len);
mp[num] = len;
mp[num - l] = len;
mp[num + r] = len;
}
}
return res;
}
};
```
### B
```cpp
class Solution
{
struct DisJointSet
{
vector<int> _id;
vector<int> _size;
int max_size;
int _count;
DisJointSet(int Num)
{
for (int i = 0; i < Num; i++)
{
_id.emplace_back(i);
_size.emplace_back(1);
}
_count = Num;
max_size = 1;
}
int find_(int p)
{
while (p != _id[p])
{
_id[p] = _id[_id[p]];
p = _id[p];
}
return p;
}
void _union(int p, int q)
{
int i = find_(p);
int j = find_(q);
if (i == j)
return;
if (_size[i] > _size[j])
{
_id[j] = i;
_size[i] += _size[j];
max_size = max(max_size, _size[i]);
}
else
{
_id[i] = j;
_size[j] += _size[i];
max_size = max(max_size, _size[j]);
}
_count--;
}
};
public:
int longestConsecutive(vector<int> &nums)
{
if (nums.size() == 0)
return 0;
DisJointSet disJointSet(nums.size());
unordered_set<int> nums_set;
unordered_map<int, int> nums_disJointSetID_map;
for (int i = 0; i < nums.size(); i++)
{
if (nums_set.find(nums[i]) != nums_set.end())
continue;
nums_set.insert(nums[i]);
nums_disJointSetID_map[nums[i]] = i;
if (nums_set.find(nums[i] - 1) != nums_set.end())
{
disJointSet._union(nums_disJointSetID_map[nums[i]], nums_disJointSetID_map[nums[i] - 1]);
}
if (nums_set.find(nums[i] + 1) != nums_set.end())
{
disJointSet._union(nums_disJointSetID_map[nums[i]], nums_disJointSetID_map[nums[i] + 1]);
}
}
return disJointSet.max_size;
}
};
```
### C
```cpp
class Solution
{
public:
int longestConsecutive(vector<int> &vec)
{
set<int> s;
for (int elem : vec)
s.insert(elem);
int longest = 0;
int cnt = 1;
for (auto e : s)
{
if (s.find(e + 1) != s.end())
{
cnt++;
}
else
{
cnt = 1;
}
longest = max(longest, cnt);
}
return longest;
}
};
```
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "daadb9b98a0545439c14e91a3c4c1b24"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5e8b6573c414422b96149e1426ef77f4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "4fcba10db64b410caaf46e7382694efe"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b6c2ccb59c3c4bbbb34157ca30736e7d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "732941eeacb244b4b09a77736c2235b5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a646669108a343a29ad09ace6292d675"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "fcae274ca8204cd3a0127bc7a246efb2"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "656c7aaf3a9a4501a0acf9ae97c64225"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "03d7c968fbd947b7839d55cda987f957"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "880a2e64223646969b4f5cbec063c6c2"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "436d7f604f3148719640ef4e1f259aef"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7e15a60056114ed3823ffa14baacfc52"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "11d24e0268454dc5862b2904b218357b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "49b8393d9d9340019f988c2fb0af1a28"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "919de84d291a4d43ab328a3c82b8463a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e35ba70494bb4edeb14433fd1675333b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "efc83d2975444730948155122314df6c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a700ecd964f741f288ffa14d14363a5b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "adc8680ea7b24d70a1ffdd603056e032"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d6591d3cdc5f4e8d9d9272b849d6ea1e"
}
\ No newline at end of file
......@@ -33,33 +33,249 @@
</div>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
Solution sol;
vector<vector<char>> board = {{'X', 'X', 'X', 'X'}, {'X', 'O', 'O', 'X'}, {'X', 'X', 'O', 'X'}, {'X', 'O', 'X', 'X'}};
sol.solve(board);
for (auto i : board)
{
for (auto j : i)
cout << j << " ";
cout << endl;
}
return 0;
}
```
## 答案
```cpp
class Solution
{
public:
vector<vector<bool>> st;
int m, n;
void bfs(vector<vector<char>> &board, int a, int b)
{
int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
st[a][b] = true;
queue<pair<int, int>> q;
q.push(make_pair(a, b));
while (q.size())
{
pair<int, int> t = q.front();
q.pop();
for (int i = 0; i < 4; i++)
{
int x = dx[i] + t.first, y = dy[i] + t.second;
if (x >= 0 && x < m && y >= 0 && y < n && board[x][y] == 'O' && !st[x][y])
{
q.push(make_pair(x, y));
st[x][y] = true;
}
}
}
}
void solve(vector<vector<char>> &board)
{
if (!board.size())
return;
m = board.size(), n = board[0].size();
st = vector<vector<bool>>(m, vector<bool>(n, false));
for (int i = 0; i < m; i++)
{
if (board[i][0] == 'O')
bfs(board, i, 0);
if (board[i][n] == 'O')
bfs(board, i, n - 1);
}
for (int i = 0; i < n; i++)
{
if (board[0][i] == 'O')
bfs(board, 0, i);
if (board[m][i] == 'O')
bfs(board, m - 1, i);
}
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
if (!st[i][j])
board[i][j] = 'X';
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
int n, m;
void dfs(vector<vector<char>> &board, int x, int y)
{
if (x < 0 || y < 0 || x >= m || y >= n || board[x][y] != 'O')
return;
board[x][y] = 'A';
dfs(board, x + 1, y);
dfs(board, x, y + 1);
dfs(board, x - 1, y);
dfs(board, x, y - 1);
}
void solve(vector<vector<char>> &board)
{
m = board.size();
if (m == 0)
return;
n = board[0].size();
for (int i = 0; i < m; i++)
{
dfs(board, i, 0);
dfs(board, i, n - 1);
}
for (int i = 1; i < n - 1; i++)
{
dfs(board, 0, i);
dfs(board, m - 1, i);
}
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
if (board[i][j] == 'A')
board[i][j] = 'O';
else if (board[i][j] == 'O')
board[i][j] = 'X';
}
}
}
};
```
### B
```cpp
class Solution
{
public:
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
queue<pair<int, int>> s;
void solve(vector<vector<char>> &board)
{
int n = board.size();
if (n <= 2)
return;
int m = board[0].size();
if (m <= 2)
return;
for (int i = 0; i < m; i++)
{
if (board[0][i] == 'O')
s.push({0, i});
if (board[n - 1][i] == 'O')
s.push({n - 1, i});
}
for (int i = 1; i < n - 1; i++)
{
if (board[i][0] == 'O')
s.push({i, 0});
if (board[i][m - 1] == 'O')
s.push({i, m - 1});
}
while (!s.empty())
{
int x = s.front().first, y = s.front().second;
board[x][y] = '#';
s.pop();
for (int i = 0; i < 4; i++)
{
int mx = x + dx[i], my = y + dy[i];
if (mx < 0 || my < 0 || mx >= n || my >= m || board[mx][my] != 'O')
{
continue;
}
s.push({mx, my});
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (board[i][j] == '#')
board[i][j] = 'O';
else if (board[i][j] == 'O')
board[i][j] = 'X';
}
}
}
};
```
### C
```cpp
class Solution
{
public:
void dfs(vector<vector<char>> &board, int row, int col)
{
if (row < 0 || row >= board.size() || col < 0 || col >= board[0].size())
return;
if (board[row][col] != 'O')
return;
board[row][col] = '+';
dfs(board, row + 1, col);
dfs(board, row, col + 1);
dfs(board, row - 1, col);
dfs(board, row, col - 1);
}
void solve(vector<vector<char>> &board)
{
if (board.size() <= 1 || board[0].size() <= 2)
return;
for (int i = 0; i < board.size(); i++)
{
if (board[i][0] == 'O')
dfs(board, i, 0);
if (board[i][board[0].size() - 1] == 'O')
dfs(board, i, board[0].size() - 1);
}
for (int i = 0; i < board[0].size(); i++)
{
if (board[0][i] == 'O')
dfs(board, 0, i);
if (board[board.size() - 1][i] == 'O')
dfs(board, board.size() - 1, i);
}
for (int i = 0; i < board.size(); i++)
{
for (int j = 0; j < board[0].size(); j++)
{
if (board[i][j] == '+')
board[i][j] = 'O';
else if (board[i][j] == 'O')
board[i][j] = 'X';
}
}
}
};
```
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a3aecbed38d64d64bf4b8bf3e15e9299"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6df6cb91d5f8484c9ab2409b9fe6d854"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "df4e1cf946db482483f90f1bab98c123"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6ff80de10e964eab90b3a79e51bd5e3b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d160b289d601480d9196307cf9bc3af4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "11317f6e2b3d435595ce32558fe30fb7"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6fb4b2c92ee8414f881f759ab8520572"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9123c1a844c74efea4702e102c31548a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e331d492c24b479383778a63c5f9a2c7"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d3edd0edca8440578e30a448a8af2f63"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ed2ee7c0f37042d5b4adf16663b9f4b7"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2daf9dfb1e6e4ac1b12a7d11d64600c9"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2951640ac01646369cefeb4c48903905"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "28486d69b0eb42e1acec7c55ec43d5ee"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "bd2665b70aa448068bba3399b95b11ed"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1fbf4f117392439aac363595cdef6fa4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "251e6f305b1f45c19fc9dc2827943bee"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "39932d0226654481890d2a008648a8f5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9b812dcf701c4c57b4302f17354e5176"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ba08167d4b2b49a6a55afab018358382"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "be2c2f901f4347ab8b3969c58cdbc74f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0bc439ea08d24a7db3013a0a6dc5fc6b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5c3440d4aa364533be444e4452f284b5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a8c2acfed25f4d91b39e892ae27449e3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "71622c8ce7184e94a6250bed4850957a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0eb57565424d430999469b071d71d7bd"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "4c5113e74c4749fea37b80f3acb43be2"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a7248577d79348c0b392223b58b9305d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0477ca8c5c4948559486c59e6f0ee6fa"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e2c2b6032d2d441a9936476bb3c1a6c5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0028da9e903d44f2b9b46dfeffca5458"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5cd1f37dfa0a4ada847eedcc222d127b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0209374b0d234f289e8b5d4930be5788"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "725ff052dc5b4f21ad2cca00898125e7"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "26c5226bc1a6431698870e18793c2c8b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "441e6b155c9c48b086041fb1cf14e5c7"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5153d58b7d624ce9873e531da1aebdcc"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b730cef88c534c488a3a3eda5586a05c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5ed3029d7db346f3a2ccada2d29c4db6"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f46872c2e0e24314a0cb9a7866a8a882"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "aae14ec3b4154df09d4c3c85a0d299f7"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "155f4930775f4ceab42c8551077b2050"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e24c0f5e13c94c7f830911eacd3072c3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "fe9fd61ba9f342438c35b5ff012045d5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "21d33101880d470685d85b0d0330103a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f3533283ef4b49389195db476b977277"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "df2b140bc3f6423187cee1d96cbda2ee"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3b0b415c69e940159ccd5a0738244c59"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7175a1cb92a142418583d4ff437923e6"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f335193f017b46f1ac6751e84ca0b290"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9a9923b5cb9b4697a257953316fc69ae"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "76a3c8fe2dac43c8a550a865e6bdf262"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "4c20bf9cc849449e8fde790e7106af0c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "bdaf7d3a46ff48c994f61715c161a79b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ee44094830f6474e852119bc8198b88f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1ad489b85904443abca9e4ef77a4ef94"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "08f2eb764ac2418ca57f1d4d6a4422c4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "cf8d584af7e64d58b8ce33fb56a3d7bf"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8321585670854c56b5fd70614a7274ba"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8ee3d73c45ac45c398b6551fe8a8653e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9327489a731147328bf611d542a789ee"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "745f01348b8446d6a574a24b703bba84"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "05e7bb943ee647f3afcbb1cd30316bdf"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a686de3312094128a17c2503b9f7d60a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3dd0e54025b54b33b75807eecfbe78df"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b71eaf6aefc348c6bd95c58c1664bd3e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "96120b21a68f40fba420c979dc134f62"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "123c4b1bfed24da08b182f2fff4ab207"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b2b82e4d2378475b851d30ddeaf10862"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "80263fdd4a244a00ad6bcefed1627a38"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2613f916a8ec4360ba911e16c0cf761a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "dc45a6534ede42d88c330643e96b8c54"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e49afafd152a4ca2964594ee5d16539e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "797bbb56090541b5be6eada554048579"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "06cbc4fa28854976b639f1ec295ec018"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ed89126c20a042dabb5f9cb512449248"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6ce1c055bb3946638e39f3e14ef605b6"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "29614ff0a545435dbf4f584fc4e58415"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "fcfc94b61dd3421b8787258f3d9d1615"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "bb908420b5de42fc8c118176101993ac"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "daf5eaaa54174d08aa4901a921e06327"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "665c445020bf4a138b9798bc92042215"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5bd7c6b4c91a4feeacb87544047eceba"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "60d1caee75e0429a9d5014265a6f2f69"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "652c05e08bdf4891803dceb8f41f8c4a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d05a4a0e45fc43d6a159793ad73981ab"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "08bda717378f4aca8839d6aaa64a434d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ac67829c34a14badb750afe45f929011"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "bc352a7dafc24856a77b039c260263f8"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "38b5b539193a4e5091d5e1ee6cd0840a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d137a0bd9b4049df8d1ac3c74a802de4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b3f60bb102b64ee682944729e98c0f9c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9a93814d00f84efea4868bff0c7236ab"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "4340eb70d41442aa8287e2bcac515e33"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8c138c51ac704f7cbd87b7866ce14413"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "93b40affa1f84dfeb7fcb52d6ce197fc"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9af2c7b6c3654a86813fb6bd6129e4dc"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "559eb9453df24aeb8347b7fce601bb7b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "513693ed395f424aac983787d8a99bdd"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f5c1d5e790bd47e08e6507a4deb86b1e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3607f832245545ee85197cab0b9b27ba"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8fd5472669704131a597cea53b75912d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9a6762ba20094b268e226f69999c1458"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c4a6fa790e3e42ebb8fb7a1bc2d5760e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "23326d5ccd254492b79c66ce422a6f32"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0216f91d9d6b4924bf0739a53bdfc60b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c27e2cb9dba7416884f31cbf4358fe81"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "28537fad581d4f4b8ff55ace13fe066b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c809e79528614f4a9ab1fd09abf6a971"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "317518ec1d394ef0b9247c48f6168386"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2a92a5de126041e69b9aae6548faad6b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "07e9cdcfd75841f097bb8aeb9ed8e71d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "13b95931f8db44b8946350d1af6fc89a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8be250de302a498fa724b65a99cc442c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "33e1947677c14f50a2e19087175678ab"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5a87786a1ef94821b623cb99a501671e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ab69df6215724c2e9cd6b896b616d77c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "13b1e1beef2044fdb599f30ec7d0f486"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2c016ab55d6d48ec9168e8a8de276f89"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d52c30b1aefc40648b60317a3c9fb82d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b528cfb536f04f79b9c7c84459912146"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b08fb743677f4ad09be4c49fb9961950"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7b36a7d56bf24619be914b628ce106a6"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "27857b9ccf794af5b2847df2eb4855b3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c5e896d9c40c4f9786721d4b3b2c9800"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "24868eac930543ccba7a3f9da75c3843"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a4f262a175b649d8bb9365ac967d2648"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "874a101eaa40415b8da8b7649e0674d5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "283f503ecadf4f42a38dde1065442653"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7efefe6de5c24e5a9272b912e4439dec"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8ea474d379c34a619d892afacc1f0926"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "dfb037cfe09747e0b035c91463ca6e56"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "60aaf7d35f994c8fad067847c6afb2d2"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "af34129617484643aa26d0a4d508719a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3df5951fcac74b3b8e6ca55348c0c81b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "798157ca26114dfd8ec3414812f7935d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "48fdededed1245729ad19c0199981186"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d1199df4ad144bd6b66d2f049886fc5b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "027bae4a6a214f79b8f4a2934a2fc0df"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3c2569f83a6c45fca5266eebb6c39196"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "49b824f44c7f4363a86a27c5ca2cfd4b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c3f2be39397041a588c11c187cb9ed04"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2abe6c633ff044c48b175e1cbf0a5898"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c91007ba576f4c60af829fb83ebe3002"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2605b4f3a08b408881690696a8435856"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "668e98a99a394648aeff7283ce5b776e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c7f196ba32be4a1dabea026bf1b046a4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "61485632bb4a4812afc26686831f9bc9"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "811f98cc66fb47298a78544a81517106"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0cb18f2425d64694bfc20818ccae20ba"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8a5ab4f2aa024d3483b1ffb654e90259"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a5a9d8c9ee8149f0aa1e90fb9d67131d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3ed4591331554e5ab513d6e925dd6f25"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "20e6ee2293184afa9a23dc3837af95ec"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "bd8726aa4a734fa8b29aaf66ca527424"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "65516d421e344dbb89254d5d07446881"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d3de4cbe62e34eb082acb70c88f2bc92"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9aa7f4fc267f4addab6005ea0fc6847e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b089c8218a1c460f81c0bf451a218a85"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "744e758d932042029de08f0f9f97328d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5d66b27f97f24ef09c14d8987bb60cd4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9a99682369f24e81b09a2bd2d41c25d1"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "261b2d9194454ade9affcba1fba6f3ca"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "34934a8b54674e538d45b4d7b0dd42b6"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7b521e53b13e43b78e6b36bd58d2ad56"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "093a06e733b54e038ac459eca4e5a4d8"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8f0a66d1cf2b49b9a4a816f2c75b0206"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7b6e385a575340349ed62d5876394fd8"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "4189dd9276dc42deacee229cae8b3556"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f8f00403c2034e6c8de9e2e61f578156"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "112f82b04bf947c0821c1775a71e6329"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "4e5f910bde7642df975728b331513db5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7b38b8e943b54f9498d9139c88d4eff5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2809fa149be4463ea4a76b17f457dd03"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "58f4543c464f477cbf141019bb0c9cfa"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "dff40d49d23246e89935e5d2d02c063f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "924d2a6ebe8e46b1af6ad5735f5546c3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d436393c9e0f4b4ca2b7a5bb5a766938"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e5b3a722fc9d40499815c33ae4a91d76"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "44189bdca8924a0483bb369ae2a29c82"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "98bcc845a5964e4fac542f0da8012cbb"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e9044ed077b04759bced4bf0c3c554de"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c371a5425f724234b0433743b1972982"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5583a4244485411c9656393e7f4081d4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "fa16392ce67746429a4a991bd994f134"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8d4f3b6689fc4beb9e15c4b644e1a7a3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9d23abcf410340a59e71be75db41c7fd"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7fbee9441b574176894d8bbe96020a58"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0db34e085dc9463c8c59781f1adf3601"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f5ce5ff4c37744dba647b22ac1d06f08"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3b7b12b7310a437b8cff2ac3dfea0158"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7e62a8d481144a789846af8ef899e89b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0c47d84e1f2b405fa906b3a1ae88fb4b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1f3aefda64ce4eedaf24ebc5df10f40e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d7e7fbf9c3a24a3ca504149e28aa0a5e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1c1225fa89c5419a9af1aebfe0b384e3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "fa2ad79cf3024754aab3c4cd8b6cfeda"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "4cec2f16217342a1b368c89f6810b74b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "89e3a1c3e17543f0a6995665d3fa95ec"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d74197ab127944a7a1846e6a70272dd0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3f0fd1b0a5944ee78e9fe565ed5c8a54"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "eeea2222668e4c3fb83958925ba1cb63"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "db0abbadffd544ae8530d36fa0d80d14"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9797218b7dca4b889a62521f5c2855a0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5b734f63971d4f32a46b4472db5a6abe"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "19383ea953eb476099b2c19104732749"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7f4deed3cea849c3af1becb982beab64"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e6d73a8030bd4a2aad24408130121a26"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f97071e14c0f424794fb52e0847dbca3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "69a1699ede244a6d932c0d0123ae799b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b8167f3e016440a8a8a215e892c57246"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6c1bcefc24ed4f28aa27942a372a6bd2"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8d6969ee67ad40668f0a29a42a05f61c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c24b7baf973b4cd693d06c08f55851de"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "27f703969a34484e883d257f9f9298ff"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1ae68ba4e28146bc8ab068c6683f6662"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "67d6061c3e6c40e0b54fbfc84fbaa840"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "dee7e275414d4c9a9c136ff79ceb3a5e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2369a9f1715a4bbc97cf2a261d97c38b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e2321f8f89dc4af8824b0cf4bf3bf420"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f38a6d23ba664971b95ad81b83950370"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c9ee364ec9d0473eb53760791eafb5cc"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "625dd8456df8489f83a423540216b0f8"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b097a03ea5ab49d78f0acb21c56976d8"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e8de09add8454b6ba8283c7d3a73fa5a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "da3f6aece4bb4b56b7c9a7d9dbf586ab"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8358d5546f524133857e9ec58cdfeffb"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d5d4ee011c584e51a8bdf0683e42ab41"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6dacc8dc57fd415f950381b3ee9d2322"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "38f06f3459594e8994c9bc745c05a85b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "878d3732302745bea673c002727943da"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "cc6f4ba6da61428aa6f9b274de6dd756"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "309305c839d246fdb4989c28b6d56f5f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8f4c08d7b93a4cf1981b44e218b714f0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a8cf0c25e79140aa9c22e9dbdb81aa02"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "701d3bfb25fc4468be1fd86be55383c5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d2e67d0ea04d40e8b804eb84c11d7d9a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c7e147728b5441688b9f567c78622085"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9f11b5a10928485e8df1b8a5d338f15d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f82a818354734898aa2d18c1a7d89fd5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "05a63801a16745ac911b90500980efaf"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "97a34e2969ed4690a6a48eb12b1a8b11"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "38132143550f4c92988e4c38f97ae244"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d0f4718cba9743f290aac9d1a929dd58"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ce12278bd805484ba1977e0b6f728f56"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6c654375f42f4b3aa01e557050cce667"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6a59de444f9b415ba3c09715accdaef7"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "37401b74931d48d1ab194b1299ff050e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9ce53606e9b34ef6ab5657f8c29c4d2c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b4f108460bdd426ebd60da41c564e557"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2208b46fc4cf442db0cb79b54c71994d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f956ae6e8a38496b8dca2dfcc5026b6d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "daa01113466d4d638c48242b597f9c01"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "97e3284e3b6045718734fded911268e1"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f08cf2e8e60d45c89255c6dcf1c4f0e1"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "dbe5a8bc4cc541e8a767555f618db42a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "38fec05ed04a498595fa8a579642fe93"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "51be808d16bb414798ea662f6d3ef157"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "23af725fa7e04cea905df78ca52e4ec2"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "045c687f6d1f48f2a06ef26c02b1d5d3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c73133004e174d72a65d6f9520eb4f32"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "91f4c03fc2be4c8ab7ac5430cd11c09d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "288a444549e2441c90ebcc3e5372dac1"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "fdb73f4a4f164a989a387213579cc904"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "837c383c16c749069dbcc02b66d163b4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6c1ed935d7284c92ba30932bc06c5453"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9bc1aead94d74ca68f51f86f94835496"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1193a49a3f464f1b9cfd1a7c010c8ec7"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a107801b4db540b68035c3280cb997b0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9d257ba52137472885acb53420e1a9ae"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6677f5e8d889425eb489ec7b116890d3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "321b69a94aff4ad18011eed88c010b3d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "33111ec5d8f44d5f8066df17615565fe"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "002d7454174a425c918ac85ca75a2bad"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9b9242a2c6b94f96bfa889f68f069d0f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "98428be550bc4388952b9f36491b5538"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "dbb59682b42941f58dd6ae452fff42da"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "24d898b0bdbb413091c130329f5cb064"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "04f60aa553494ac2b56c975894cce5f8"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d41b267910994f30893cb6ab80a73545"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a2661e8582a04268b9ca7f9320bea573"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1d4969e4e3fa41b0a683ec97d2c4f743"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e416b53b4acc492898cf844d75e6de54"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "54e4a816013949f8a9231461bb1c5fd3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "4336824b17b84f28852d7e554e6e4274"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c1a68e85e9884b39b7c761f0a9ce1a1b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6723d9f4015349d2b6e6478d25c9efbf"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6a772a6709484d7182f6a792f23be664"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e10e873217664a4ebd2f9b146acda317"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8b496907090742028c44e804f19ef0d9"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "be336779d4a944ce88dad05227c6cc5d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2d3f7c34a9244d4d8caf3e5f9a70528b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "4f12e4bd3efd4d5785fc0dd7df0e2898"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b0ea6cbabc364ad6a42e817ece0c5554"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "89519c1c7d4041fbabe7d6abe98552b7"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f8cf1046e2f1499594ca5b5df2d47237"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f125a429fa3f4a39ba1f0a4acbe046d3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "99235c36d55b4a21a73e9ed80b2ba576"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "62249394e13445a3b18a90075d0f10e6"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8a69bd935f484074aa6ba47fb8f55389"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "541a83ab405a4af8afc041ffa65f343c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "dd61df02d78a447ab26a671bb9b511be"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "093804079be748f8b527fdb9e5e11df0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "64ffb20797e24752a33b2317948cedb4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a56192607b494fa8860b6adbba04fc52"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ae7e26239b2f4ba6bc3cc7e921ebaabe"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "66dfeab31c0c403ba52b069e98ec8051"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2d41392874324483a7bb8b283fcb01c0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ad0eaae16a6d484487fcbf26e4a5f68a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "09c94fd315ad4712b1b8c284680e1dec"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e8e14aad4ba8436cac9ae605dd2f5e2b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ec38aeda59cb49e2972d9d6544d1e708"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "088631b37039488f87db2040bafcb879"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "dd045d059ead4e46a4ad23b310254746"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c7d38af6a5d54fe0adbdac904b98fdd4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "318fd33ea8c04042be0b6a41a178d576"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1f401e5ef1bf4c7594accfb8418e1a8e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a5b538567b2d498fbad8cb2ce3dd0559"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "751c9fd01da54fe1a2042b8270752f28"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b96c0154fb004f718acfc448298905dc"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e2acbf75c832445d9a4424b71f740e81"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6f6bcf80e1084f65a8688464d192608a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "94400c968b584849a20506018b1e0ffa"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "01cecf8f5b1c45dc8d94431b4edda3f4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "334284244b09418b80602edb011e8fc5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1539901bf3984a55a66e60359db5d317"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e602501cb7df4908bd99e06305918e80"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ab1a55945c7c494697dac4a62752852a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "82d16ad5688b45d8bc0aff5e476d0fff"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c2d2ed6c7988428db1781e5be4474590"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f9493ac774cc4fd7803dc38f7aa7a8e2"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3ccf823bf62a4976b132ed617f571b7d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d45c21b7f70e46f5bc5668b8df2f7139"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "bebfba344b58413d8c7c817bf2d6116a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7a05775ab19b4b28af761e0fe52395cb"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "25d869acca5e4e44a4cb96d41a84c45c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "447c80f74a7048f7ac3c354d8061ff2c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f9e031c60eea4917a96a46ee5c1bc3ad"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3337b60d32eb4891973127157b4badb0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "fe932e4971974b72977184869b64927b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ea3c7d52459f4ca2a13b19902e1318ee"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "548a3cf2e860443a8902a5d55fca84c1"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6466a857f43f42e893955d27bc7a0937"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1a3c45f905a040a4b929bcfd55f7c92f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "75679ce0e7f6425b9e6fb00632e4fa5b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d11c5b6d35794073a12bd301e8283b8d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "50ea05e93e594ebaac8a836361ecea1c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b34dce6078d44089ac3a9febe775dafa"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ce9da512bc0e4968a08f33d5ca43b7af"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "52da24525feb471ca8663ea2fdf82bd0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0db748a1b7c9417187d4ac8ebb8daea2"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7430938fe1724f68b8e265083410eefa"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "87a1acf5288e4e2ea94e4cc19a5609c3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5061bf667a4f4de7aa2680b7aaca2ae4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "49e1b8a4d40d42a1b4978e3967b0a9d0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7755e4d656ae42e18b2a98f9d6405415"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f46874e6ab474f908433bfb4219bfe1f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b8081424899948ddaefd946b995d5830"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e9caf2c292b34d45ac240f13143b5c33"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3b766dd46834493cb76ef45879ea14e7"
}
\ No newline at end of file
......@@ -54,33 +54,213 @@
</ul>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
Solution sol;
string res;
int numerator = 1, denominator = 2;
res = sol.fractionToDecimal(numerator, denominator);
cout << res;
return 0;
}
```
## 答案
```cpp
class Solution
{
public:
const static int CACHE_SIZE = 1000;
string fractionToDecimal(int numerator, int denominator)
{
if (numerator == 0)
return "0";
bool isNegative = numerator < 0 ^ denominator < 0;
double doubleNumerator = fabs(numerator);
double doubleDenominator = fabs(denominator);
double integral = floor(doubleNumerator / doubleDenominator);
doubleNumerator -= doubleDenominator * integral;
int len = 0;
string cache;
vector<double> dividendCache;
bool isRecurring = false;
int recurringStart = 0;
int i = 0;
while (doubleNumerator)
{
doubleNumerator *= 10;
len = dividendCache.size();
for (i = 0; i < len; ++i)
if (dividendCache[i] == doubleNumerator)
{
isRecurring = true;
recurringStart = i;
break;
}
if (isRecurring)
break;
i = (int)(floor(doubleNumerator / doubleDenominator));
cache += i;
dividendCache.push_back(doubleNumerator);
doubleNumerator -= doubleDenominator * i;
}
string ret = isNegative ? "-" : "";
string tmp;
char c;
if (integral == 0)
ret += "0";
else
{
while (integral)
{
c = (int)(integral - 10 * floor(integral / 10)) + '0';
tmp = c + tmp;
integral = floor(integral / 10);
}
ret += tmp;
}
if (dividendCache.size() > 0)
ret += '.';
i = 0;
if (isRecurring)
{
ret += cache.substr(0, recurringStart);
ret += '(';
ret += cache.substr(recurringStart);
ret += ')';
}
else
ret += cache;
return ret;
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
string fractionToDecimal(int numerator, int denominator)
{
typedef long long LL;
LL x = numerator, y = denominator;
if (x % y == 0)
return to_string(x / y);
string res;
if ((x < 0) ^ (y < 0))
res += '-';
x = abs(x), y = abs(y);
res += to_string(x / y) + '.';
x %= y;
unordered_map<LL, int> hash;
while (x)
{
hash[x] = res.size();
x *= 10;
res += to_string(x / y);
x %= y;
if (hash.count(x))
{
res = res.substr(0, hash[x]) + '(' + res.substr(hash[x]) + ')';
break;
}
}
return res;
}
};
```
### B
```cpp
class Solution
{
public:
string fractionToDecimal(int numerator, int denominator)
{
string ans;
unordered_map<long, int> use;
if (numerator > 0 && denominator < 0 || numerator < 0 && denominator > 0)
ans = '-';
long numerat = fabs(numerator);
long denominat = fabs(denominator);
ans += to_string(numerat / denominat);
numerat = numerat % denominat;
int point, x;
if (numerat)
{
ans += ".";
point = ans.length() - 1;
}
else
return ans;
while (numerat && use.count(numerat) == 0)
{
use[numerat] = ++point;
numerat *= 10;
x = numerat / denominat;
numerat = numerat % denominat;
ans.push_back(x + '0');
}
if (numerat)
{
ans.insert(ans.begin() + use[numerat], '(');
ans.push_back(')');
}
return ans;
}
};
```
### C
```cpp
class Solution
{
public:
string fractionToDecimal(int numerator, int denominator)
{
int m1 = numerator > 0 ? 1 : -1;
int m2 = denominator > 0 ? 1 : -1;
long long num = abs((long long)numerator);
long long den = abs((long long)denominator);
long long t = num / den;
long long res = num % den;
string ans = to_string(t);
if (m1 * m2 == -1 && (t > 0 || res > 0))
ans = '-' + ans;
if (res == 0)
return ans;
ans += '.';
unordered_map<long long, int> m;
string s = "";
int pos = 0;
while (res != 0)
{
if (m.find(res) != m.end())
{
s.insert(m[res], "(");
s += ')';
return ans + s;
}
m[res] = pos;
s += to_string((res * 10) / den);
res = (res * 10) % den;
pos++;
}
return ans + s;
}
};
```
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "04661f1502fb4a7caffd65bf9804d981"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "04b64ef3caab41fba230b1589fd46b7e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2ef6049026cf4dc3b4c12551fda8fe5c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7d7d47c893fc4675872bc9b75177214f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f82dfdf0b4704fdeaa0989cd7f2e7fa0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "04c31d33b27344cfb96bf1b2179b6798"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ec7bbd853fda427f82b06d9a006bf406"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b3645dc3cd034093bede4f47df5f25cf"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7c76ecf38c0640cc92d5f33e6ac5e406"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "cc10cccca673444cb35c834ce09e5296"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "38295a128d5e404fa7fdf0c05c8b6469"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f1b95c135c5d4ab1ac4c5cf73741c907"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6c8d358e60754761a568b8a2a22ee0f8"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e61b6b4cf9584caa960bf1906c388c95"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f4897899fcb74526b14cc76b0e1eeca6"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "012b29fa9d764d908d42e16cfc803993"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "16a1527854e74455a5284d347e8dfc26"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "18f41bad33934fe6aa0c2b16c7ae5c16"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "53b49f9b686d441eb755bad68ff3ffc0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "fcde4897474849d4ab629be1797b8aca"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2eebc072f17e49878b6a59251eb0c52c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b67f602a50b349db8fb21a73afca41e0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2c98d44a52a24e3db4adca70ce51f7f2"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "70e0f7713a84410da8795d0f105a911b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0a3322c57b764ff486adf31cba87259e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5711c801f88742d7a8f5d678f0a3ba92"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0cf9f67fbe4b4f6bab0248ad4dfdafa6"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "01a8f73bdefb4a25a6a0dfc743555685"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "605f6a8437014380b3a3664ee6ed146c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "28f04f298f40476b8687cf64fe4accfd"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a7faa961fc454505bf3d14798e550eec"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "837ee3d12dc7461ca1c70fe761c44ff2"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b7ee0a3b44ee4c7396bac45eb201104e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a76101bb61704e2ba01b8a2ce372ea11"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "adda6958148c4598b7cd0577952e8246"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f2bb4e760d094e8f85d8b2ed13484138"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9666fd8c55b1466399506b088f7218eb"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "be176939f89847b1a5ed9560dfa7bb96"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "19115e24cad24adeb73d4c8d083f2cc0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "152f843f9d42408bb307d5e25d370efc"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "fd243acd14e3480ab5267191e077004e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3c29a6e8630d48ceb7b8bb1ef3b32fea"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "81c83fb16613489a843276b984c683d3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b2be57c16ed74f8193f3ff34c1917582"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f9c7b89a8f074820b48ed6c6ea062e03"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "53a974f192a34d6b93a07817db6785d3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3fc74ce1a43a4cddb92b9fb0473ead2a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2b80201e87f54fc2b80b68f3c0458f00"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "92c9a81622984977b0defb47a46c7964"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "de6081723d3543a4a6eaec6420764818"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c43209e1f56647b7a94aca1fd1dbf7c8"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "23da1633d3634ff59441af42fae170aa"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7f33f8ccce284a8eb24e7a12c6164ba0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0950f354fb254e94af535def2a1ba8cf"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1d461773030941478787fed0e4f9738d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "bb2d9083b13c474fa267dc044c86ab74"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8e2ba7c83256477b9993c54c12d76d15"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "59d8d6685a704560a093feece2137b84"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "02a087cb749748a7ba2b6d2a474f71a4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "07ef55ee22f0435eb744de43ff06cb2f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8c8949e2e01b496f87874a0cd73a6ce9"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0f6a4d659c414d5589f5f36a0f7ebde5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "925835a39a7e40cbb70d3daff48c60e3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7af86e7eb65e4816bb034ab61dc7eb99"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "04485934df374b75b7107bc4ff1ba95f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0e7ff1de9dc54c96b2a8729d01ab74b6"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "dd4d8e3e554a42b6a031f66be799a3de"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7ee18f0dd7b64c9dbf6d05c4c976a9e5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "cee27ca77b8e42aaa334bd8cc3f21387"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f60a15ff1b5248f29475f0f03d8acde0"
}
\ No newline at end of file
......@@ -57,33 +57,197 @@ bSTIterator.hasNext(); // 返回 False
</ul>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
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
/**
* Your BSTIterator object will be instantiated and called as such:
* BSTIterator* obj = new BSTIterator(root);
* int param_1 = obj->next();
* bool param_2 = obj->hasNext();
*/
```
## 答案
```cpp
class BSTIterator
{
private:
void traverse(TreeNode *root, vector<int> &res)
{
if (root == nullptr)
{
return;
}
traverse(root->right, res);
traverse(root->left, res);
res.push_back(root->val);
}
vector<int> inorder(TreeNode *root)
{
vector<int> res;
traverse(root, res);
return res;
}
vector<int> arr;
int idx;
public:
BSTIterator(TreeNode *root) : idx(0), arr(inorder(root))
{
}
int next()
{
return arr[idx++];
}
bool hasNext()
{
return idx < arr.size();
}
};
```
## 选项
### A
```cpp
class BSTIterator
{
private:
void inorder(TreeNode *root, vector<int> &vec)
{
if (!root)
return;
inorder(root->left, vec);
vec.emplace_back(root->val);
inorder(root->right, vec);
}
vector<int> inorderTraversal(TreeNode *root)
{
vector<int> ret;
inorder(root, ret);
return ret;
}
vector<int> buf;
size_t idx;
public:
BSTIterator(TreeNode *root)
{
idx = 0;
buf = inorderTraversal(root);
}
int next()
{
return buf[idx++];
}
bool hasNext()
{
return idx < buf.size();
}
};
```
### B
```cpp
class BSTIterator
{
public:
stack<TreeNode *> treeMin;
BSTIterator(TreeNode *root)
{
TreeNode *t = root;
while (t)
{
treeMin.push(t);
t = t->left;
}
}
/** @return the next smallest number */
int next()
{
TreeNode *tmp = treeMin.top();
int res = tmp->val;
treeMin.pop();
tmp = tmp->right;
while (tmp)
{
treeMin.push(tmp);
tmp = tmp->left;
}
return res;
}
/** @return whether we have a next smallest number */
bool hasNext()
{
if (treeMin.empty())
return false;
else
return true;
}
};
```
### C
```cpp
class BSTIterator
{
public:
queue<int> q;
BSTIterator(TreeNode *root)
{
inorder(root, q);
}
void inorder(TreeNode *root, queue<int> &q)
{
if (root == NULL)
return;
inorder(root->left, q);
q.push(root->val);
inorder(root->right, q);
}
/** @return the next smallest number */
int next()
{
int tmp = q.front();
q.pop();
return tmp;
}
/** @return whether we have a next smallest number */
bool hasNext()
{
if (q.empty())
return false;
else
return true;
}
};
```
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "193ca019ea134956941015a6409c5817"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "61bca43024504079802a322418b55348"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "053990fe66f442b3b51a97d154639133"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "17fc14d2fd4f4143b59975b51d73ced7"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "01fefb95640a477881eb68e3503cf3ad"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "27c80592790a4a94866d96ea9856b42c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "39068d1c05f64abbbfff29cf67ad7b26"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d63f6dee111a4375b1759094a05701e0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "23ad744ae8ff4ba3a604f140dd16bff9"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "4ac0b01dc81d4630afdc219906fb1905"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ae1edfa2e1694ba2b3816d3bca02bb1c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "4065328c52ae45179ae555f36d0a6b7a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c07867b5117f40d2ac85e5f14cc59686"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "fb5547650a494d4bb703f725bf538096"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3c768006f93e4c4ca01f5bec646124d3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "14d8cc301f304660a79c50e6469a8e9b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "deb23990d5804582a0ffc5c258803781"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "cb64697045aa44a4a07b11fab33c2b71"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "bceaf8541dd74cf3a3bcc74658fccdad"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b4dc57256c2f43fcbe71ddc07ddcde6b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "87e9cc4114f7491288d0810f7d7160e0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d036d86c945549019f2a0695201d6b11"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "38f41beb0f6d43578bffc8194b94737d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "62da0138a43348d9a6574e0d8790e373"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6957fb38761e417398d293f498602a17"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "dd843cf6de95490e964fa119e451e18d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "bd3e0b734fb94c9eb666e12cac7b2eb5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7f5d601255df47f199235806b1d951ef"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0d790e150f3a4ab3be73af13796fa308"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "411cbf28c2b144e8b00c8ddcf831b336"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9979995519d24b67a26dbd392aad184e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e06e60db7d7b4ce39be3b63b59091b5c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f0b9de828a0644939f5d00ff69a0f7ae"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b66f23339f8b46d3a6597d806e86f482"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2db8521d7fe94845a90e9a7bbe7a8db8"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "42cdd317dfd74431bb2aea96fc1d2970"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "31912574bef24d17a437288cde64fcc2"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7f0afc06c3964b26bbe0a0b0a7d79c72"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f3c6362d35cf4ec68062148d158030b1"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9b4374a7fc254eb68f56a5e7668674ba"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5a7b39c517cd4878a048a04592a74fe7"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "faee8aa2d1b2497c98e6a91f05dd171b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0af32b37e1934133a8460a4699b3a57c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "fea5869d090a4ec0a2f3a9ab35ef34fb"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ab8057c03ed24c978ccd75cbb5a1ee71"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1e05a0b5bce44a5ba9cac4544c7f26d7"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a250628e2baa43cf9a619ddcd6c2fbc6"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e7b54e4b4f594c6c9eaaf27ea626ded2"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "23d5173d1f9247ef81173518cafdced7"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6eee35c5b5d84f96b712256fe1695dd7"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5335833701d64beba3c3b8b579082ed4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3a58c12e391c40b5a4c920ebca9c0e07"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2a9ace748b0e4e20a55daa54310d1e93"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "125e86092b8f457792242006785d2694"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3117afc6a9774f048be8217ee2674dc1"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5231f10baafe41909abb03fe5cd645f9"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7a82e5fd57294013a362161412b36537"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "77fb4ba5c8dd452f989169dfd18c4df3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "25a8a828673342b886a9d3870c83cb0a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9909ac253c7b4b44853f1c2503f0e7e5"
}
\ No newline at end of file
# 最大数
<p>给定一组非负整数 <code>nums</code>,重新排列每个数的顺序(每个数不可拆分)使之组成一个最大的整数。</p>
<p><strong>注意:</strong>输出结果可能非常大,所以你需要返回一个字符串而不是整数。</p>
......@@ -42,33 +43,120 @@
</ul>
<p>以下错误的选项是?</p>
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int main()
{
Solution sol;
vector<int> nums = {3, 30, 34, 5, 9};
string res = sol.largestNumber(nums);
cout << res;
return 0;
}
```
## 答案
```cpp
class Solution
{
public:
string largestNumber(vector<int> &nums)
{
string ans;
for (int i = 0; i < nums.size(); i++)
{
for (int j = nums.size() - 1; j > i; j--)
{
if (to_string(nums[j - 1]) + to_string(nums[j]) > to_string(nums[j]) + to_string(nums[j - 1]))
{
int tmp = nums[j - 1];
nums[j - 1] = nums[j];
nums[j] = tmp;
}
}
ans += to_string(nums[i]);
}
if (ans + "0" == "0" + ans)
return "0";
return ans;
}
};
```
## 选项
### A
```cpp
class Solution
{
public:
string largestNumber(vector<int> &nums)
{
string ans;
sort(nums.begin(), nums.end(), [](int a, int b)
{ return to_string(a) + to_string(b) > to_string(b) + to_string(a); });
for (auto it : nums)
{
ans += to_string(it);
}
return ans[0] == '0' ? "0" : ans;
}
};
```
### B
```cpp
class Solution
{
public:
string largestNumber(vector<int> &nums)
{
if (*max_element(nums.begin(), nums.end()) == 0)
return to_string(0);
vector<string> vec(nums.size());
for (int i = 0; i < nums.size(); ++i)
vec[i] = to_string(nums[i]);
sort(vec.begin(), vec.end(), [](const string &s1, const string &s2)
{ return s1 + s2 > s2 + s1; });
return accumulate(vec.begin(), vec.end(), string());
}
};
```
### C
```cpp
class Solution
{
public:
string largestNumber(vector<int> &nums)
{
string res = "";
int n = nums.size();
vector<string> tmp;
for (int i = 0; i < n; i++)
{
tmp.push_back(to_string(nums[i]));
}
sort(tmp.begin(), tmp.end(), compare);
for (int i = 0; i < tmp.size(); i++)
{
res += tmp[i];
}
if ('0' == res[0])
{
return "0";
}
else
{
return res;
}
}
};
```
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6c6e52b899a745df94fee48c6ecc192e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d17ecc01dd574de39e43d26266d5f552"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "12932abaf3b84891bf7cfbf666ab34a6"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "248c474a4686497ca6e409f238862681"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f8564ec2a3a042bc86dab90fe2682208"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a93dbc0488114d5cbb1b427fd0c72992"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8d780e27238245a6be0acb7523f0268f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c3b0aa845a2a46aca510620f1b8ab2f3"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c490547116d64172b260da174984b11f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "33ba76889e104d7eb928c51f1029df3e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "789b98140e7648d9a86f0bbb947efc23"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "34a5f227691f4b02994d98907d1bb52e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1235c13cb7434e849a1a52ffed247f69"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3ac0b60196014a4ca5745c576a892c00"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "991cc91d82f14c3ab7470883aef72ed6"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "4d6b59723ee54d4f8c9aecd7659f88b4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a060e75571c3438f9e79bfda69f25cea"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "71d0e26407994f6ba74387e117954a1f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7db1cf218797451592bec6f709ef2662"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "42ace4ddf3584c958c0a80d7f524899a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f13b1c64964c4355ab113ff2053a0fef"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6755a54e301045eab841498f809f48fa"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "bc7b151b5805479f8f3470cffbece5b9"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d3b1049ab419429d9b8f7235e5ab6372"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "daccd26f9b89408a9c50805b6c847430"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "45b54fe1d7ef4da188e7b1d6f0f979ec"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "5a6213c5fc2d4c62aa45a7352189c6c6"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "190311b983f04e2b833a95bf1657e5da"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6b86157af7794a83bf03d001cddc2537"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ba7b23c875234ccb86c4f352058ca544"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "830a1192e5a14020b391205af6a07113"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1b35fbd9756343588564925d913233a5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f562a1079429490294f1ee2e60996989"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "4a93ebb9dd90457eb203775bd17ff5c5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b8dd5574d153471fa3787d3e2816d3f8"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "30e883a8f9c34ad6b5ca47e1fa7663b1"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0500d93ea2944e4887d2bf36a59ee078"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "620938bda66341159f528dbbca73b093"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "4da64a1ff59e416dbe9db1730482e082"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "60175d820c2d4b46ba7b51cc5836c996"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9691d41b3ab94cf19bd3ec4d8e4834cb"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "696e789717ed46abb9dc536cc34dd4bc"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "11e71ad185e1455999627b2da74bdd93"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a9158654e5c54ff0862334326d97933a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "dc372befeab64d73987676562007a3c6"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "560eacef415d4c68b27d9b823fd2fd67"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "51ee117f9b2f444eb898d141e25f845b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "63bb1f9780a14bbcb0cd118c1ee3957f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d08b37719b064785acba41c75f6c04af"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f73632f782774334900e195d9c08d6f4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c3afb0c91a964aef9acf351991fb5297"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "a903fdac814b4c1f979803c1b6ec8a69"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "81cd4a578c124650a4d94f9ec53408d6"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "de73aaca1f534897b721fe6d9d3e14ee"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "52cfad14c910475abe0aef801d511c30"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ebf2ce78606d479fbf2b09d79bd2e74c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "42cb4bcf34fc4f4ab6bb879f1221d78e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "073c9a8d02874c45b7bbc2dbce837c2c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "487a3c80896443d3854936050b4740d5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "23c0fea5734e47b29cb543ca502efbea"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "663880df83d34011aa92ea05d8db1807"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e9f06698cda342029ede20d7cce4f040"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "901f0abd7e5c48748f6111349c9f0088"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "bfbf591f20c14da993b962a8207dbc9e"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "634c7949281a4eb3be8c90d1e250f6f4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "51df18547e054b8c8ae482342b8335ac"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "0e9179dafc034724a812061b28e5539c"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b3c2825fd1c844beabdf572dd5e6fe89"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8f82f5ba4ff5400a9818c7cdfc25a947"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "148533dcc2474cfb98662ed2141e49fe"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3bf5eb23819b4118b7427d4e0308af20"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "cc7c3499126e4e36ab136acd89107cc4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "40e6d0145cc7436aa1e54d79ad7c21ea"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "bbbdd03121574905a23090ec4db62aba"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d09fa84d6d8d44f2915d62eacaf842d1"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e5510fba88ba4fa29089923d357287bf"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1d6544e95a604e03b17713753da4bbff"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f23e66f15a954694b083a674b41ef1ed"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "352fe3433f054d03a3272b70aa1a6702"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b23597b9ec2c4691bc2c60a6e996ea64"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ada7908161f4406398326d355d60457a"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "c7aa6448ab6844b085288f28dff37cd0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "82fa50d89b7340b0b7671e2809db6c98"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "be46ebec27bd42188d04151768930a4d"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "fb666261bdb24043a4702de02fc4ecbf"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "cced910026d7418f8e24e1cd499912ca"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1ca7e4a3c48b40db9230efcab5be08f4"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e3c5e16171c2487483f95525f0f7d629"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7b4d3a3e21df45b9b13fe86f4887faab"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "11d5069620ff4b269116b387430e6125"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "09f9aaf11d644844913b52d51062cb18"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "42895b9aa8fa4287ad31fac72d097be1"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7aa06db0c3b649dcb1d3d546186b0cc7"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "fb1180893ac84623a9061bc074aa30e8"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "49c32f8b1a974c5eab6a51f523c23aa9"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6d13667cac1f4a9da9e42a831b57af93"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "74b3a27cb708446ba8b175c0558b3c30"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ff1560df6b4a46a6864415408b3775c9"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "38c0ae32c152430191f5860a91d3fd66"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e878431dae4c46328a01d64011a37a18"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9ac9ff06618c47269866a30205bc2db0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e8dfe11a7fc44165b76fde8bd7f96da5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "3af90265af3c47caa27df335676a5bb8"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "dab766d479244139b12087a0a610fb6f"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "4681b37bfffc490099c820792b188c74"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "8435ab5ed6f542c3aa4ca03c73a55d34"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "07136c95ed9142cbb8642c8e907a9c78"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "e720fd7831bd489c920d3fe806d1b77b"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b1ce94ba01f04c7b955026215adf93b5"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "d6730d5b994d44d8805bf5f9d1bf5c79"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "934cbc399f624046afc887f024c9d151"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9e703a044d444548bbe24039d6fab967"
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ace4205352a94b90adc4989193ae0708"
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册