- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubsequences_nowcode.cpp
More file actions
Latest commit
46 lines (42 loc) · 954 Bytes
/
Copy pathSubsequences_nowcode.cpp
File metadata and controls
46 lines (42 loc) · 954 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
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<iostream>
#include<string>
#include<vector>
#include<unordered_set>
usingnamespacestd;
classSolution {
public:
vector<string> generatePermutation(string s)
{
int len = s.size();
char* buf = newchar[len+1];
unordered_set<string> set;
f(s,0,buf,0,set,len);
vector<string> ret(set.begin(),set.end());
delete[] buf;
return ret;
}
voidf(const string &s,int i,char* buf,int size,unordered_set<string> &set,int len)
{
if(i == len)
{
buf[size] = '\0';
set.insert(buf);
}
else
{
buf[size] = s[i];
f(s,i+1,buf,size+1,set,len);
f(s,i+1,buf,size,set,len);
}
}
};
intmain()
{
string str = "aab";
Solution s;
vector<string> nums = s.generatePermutation(str);
for(auto i = nums.begin();i != nums.end();++i)
{
cout<<*i <<"\n";
}
}