forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1087.cpp
42 lines (41 loc) · 974 Bytes
/
1087.cpp
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
class Solution
{
public:
vector<string> expand(string S)
{
for (int i = 0; i < S.size(); ++i)
{
if (S[i] == '{')
{
string tmp;
int j = i + 1;
for (; j < S.size(); ++j)
{
if (S[j] == '}') break;
if (S[j] != ',') tmp.push_back(S[j]);
}
data.push_back(tmp);
i = j;
}else data.push_back(string(1, S[i]));
}
dfs(0, "");
sort(res.begin(), res.end());
return res;
}
private:
vector<string> data, res;
void dfs(int u, string path)
{
if (u == data.size())
{
res.push_back(path);
return;
}
for (int i = 0; i < data[u].size(); ++i)
{
path.push_back(data[u][i]);
dfs(u + 1, path);
path.pop_back();
}
}
};