-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path46.cpp
More file actions
27 lines (24 loc) · 706 Bytes
/
Copy path46.cpp
File metadata and controls
27 lines (24 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <vector>
#include <algorithm>
using namespace std;
class Solution {
public:
vector<vector<int>> permute(vector<int>& nums) {
vector<vector<int>> res;
backtrack(res, vector<int>(), nums);
return res;
}
private:
void backtrack(vector<vector<int>> &res, vector<int> temp, vector<int> &nums) {
if (temp.size() == nums.size()) {
res.push_back(vector<int>(temp));
return;
}
for (int i=0; i<nums.size(); i++) {
if (find(temp.begin(), temp.end(), nums[i]) != temp.end()) continue;
temp.push_back(nums[i]);
backtrack(res, temp, nums);
temp.pop_back();
}
}
};