forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1096.go
49 lines (46 loc) · 954 Bytes
/
1096.go
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
var s []byte
func braceExpansionII(expression string) []string {
s = []byte(expression + "}")
i := 0
res := solve(&i)
sort.Strings(res)
return res
}
func merge(a, b []string) []string {
res := []string{}
for _, l := range a {
for _, r := range b {
res = append(res, l + r)
}
}
return res
}
func solve(i *int) []string {
if s[*i] != '{' {
L := []string{string(s[*i])}
(*i)++
if s[*i] == '}' || s[*i] == ',' {
return L
}
R := solve(i)
return merge(L, R)
}
all := make(map[string]bool)
for s[*i] != '}' {
(*i)++
R := solve(i)
for _, it := range R {
all[it] = true
}
}
L := []string{}
for k, _ := range all {
L = append(L, k)
}
(*i)++
if s[*i] == '}' || s[*i] == ',' {
return L
}
R := solve(i)
return merge(L, R)
}