-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDay-096.cpp
More file actions
29 lines (28 loc) · 743 Bytes
/
Day-096.cpp
File metadata and controls
29 lines (28 loc) · 743 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
28
class Solution {
bitset<100>visited;
vector<vector<int>>res;
int n;
void generatePermutation(vector<int>& nums , vector<int>&temp){
if((int)temp.size() == n){
res.push_back(temp);
return;
}
for(int i=0;i<n;++i){
if(!visited[i]){
visited[i] = true;
temp.push_back(nums[i]);
generatePermutation(nums , temp);
temp.pop_back();
visited[i] = false;
}
}
}
public:
vector<vector<int>> permute(vector<int>& nums) {
n = (int)nums.size();
visited.reset();
vector<int>temp;
generatePermutation(nums, temp);
return res;
}
};