//LeetCode46.全排列
class Solution {
public:
vector<int>s;
vector<int>q;
vector<vector<int>>ans;
void dfs(int u, int st) {
if (u == s.size()) {
ans.emplace_back(q);
return;
}
for (int i = 0; i < s.size(); i++) {
if (!(st >> i & 1)) {
q.emplace_back(s[i]);
dfs(u + 1, st | 1 << i);
q.pop_back();
}
}
}
vector<vector<int>> permute(vector<int>& nums) {
s = nums;
dfs(0, 0);
return ans;
}
};
LeetCode46.全排列
最新推荐文章于 2024-04-22 23:30:06 发布