-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleet46.cpp
More file actions
33 lines (32 loc) · 755 Bytes
/
Copy pathleet46.cpp
File metadata and controls
33 lines (32 loc) · 755 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
29
30
31
32
33
class Solution {
vector<vector<int>> res ;
vector<int> temp ;
bool *fl ;
int n ;
public:
vector<vector<int>> permute(vector<int>& nums) {
n = nums.size() ;
res.clear() ;
temp.clear() ;
fl = new bool[n] ;
for(int i=0 ;i<n ;i++)
fl[i] = false ;
puts(nums) ;
return res ;
}
void puts(vector<int>& nums){
if (temp.size() == n){
res.push_back(temp) ;
return ;
}
for(int i=0 ;i<n ;i++){
if(!fl[i]){
fl[i] = true ;
temp.push_back(nums[i]) ;
puts(nums) ;
temp.pop_back() ;
fl[i] = false ;
}
}
}
};