forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1087.py
27 lines (25 loc) · 753 Bytes
/
1087.py
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
from itertools import product
from functools import reduce
class Solution:
def expand(self, S: str) -> List[str]:
data = list()
i, n = 0, len(S)
while i < n:
if S[i] == '{':
tmp, j = list(), i + 1
while j < n:
if S[j] == '}':
break
if S[j] != ',':
tmp.append(S[j])
j += 1
data.append(tmp)
i = j
else:
data.append([S[i]])
i += 1
res = list()
for it in product(*data):
res.append(reduce(lambda x, y: x + y, it))
res.sort()
return res