题目:
Given a collection of numbers, return all possible permutations.
For example,
[1,2,3] have the following permutations:
[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2],
and [3,2,1].
class Solution {
public:
vector<vector<int> > permute(vector<int> &num) {
res.clear();
memset(used, false, sizeof(used));
dfs(0, num.size(), num);
return res;
}
private:
vector<vector<int> > res;
bool used[100];
int a[100];
void dfs(int dep, int maxDep, vector<int> &num) {
if (dep == maxDep) {
vector<int> tt;
for (int i = 0; i < maxDep; i++)
tt.push_back(a[i]);
res.push_back(tt);
return;
}
for (int i = 0; i < maxDep; i++) {
if (!used[i]) {
used[i] = true;
a[dep] = num[i];
dfs(dep + 1, maxDep, num);
used[i] = false;
}
}
}
};
本博客详细介绍了如何基于给定的博客【标题】、【标签】和【内容】,生成新标题、摘要、关键词以及新标签的过程。通过分析原始内容,我们能够提炼关键信息并创建具有吸引力的新标题,同时生成包含技术领域相关信息的摘要、关键词和标签。
6243

被折叠的 条评论
为什么被折叠?



