-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path47.cpp
More file actions
executable file
·60 lines (60 loc) · 1.72 KB
/
47.cpp
File metadata and controls
executable file
·60 lines (60 loc) · 1.72 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <vector>
#include <string>
#include <map>
using namespace std;
class Solution {
public:
vector<int> tmpnums;
vector<int> original;
vector<int> tmp;
vector<vector<int> > answer;
vector<vector<int> > realanswer;
void dfs(int layer){
if (layer == tmpnums.size())
{
answer.push_back(tmp);
return;
}
for (int i = 1; i < tmpnums.size()+1; i++){
bool flag = false;
for (int j = 0; j < layer;j++)
if (tmp[j] == i){
flag = true;
break;
}
if (flag == false){
tmp.push_back(i);
dfs(layer+1);
tmp.pop_back();
}
}
}
vector<vector<int> > permuteUnique(vector<int>& nums) {
tmpnums = nums;
original = nums;
dfs(0);
for (int i = 0; i < answer.size();i++){
vector<int> tmp;
for (int j = 0; j < answer[i].size();j++){
tmp.push_back(original[answer[i][j]-1]);
//str_tmp += '0' + original[answer[i][j]-1];
}
bool findse = false;
for (int j = 0; j < realanswer.size(); j++){
bool tmpfind = true;
for (int k = 0; k < realanswer[j].size();k++)
if (realanswer[j][k] != tmp[k]){
tmpfind = false;
break;
}
if (tmpfind){
findse = true;
break;
}
}
if (findse == false)
realanswer.push_back(tmp);
}
return realanswer;
}
};