-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy path1096.py
More file actions
21 lines (20 loc) · 676 Bytes
/
1096.py
File metadata and controls
21 lines (20 loc) · 676 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution:
def braceExpansionII(self, expression: str) -> List[str]:
stack,res,cur=[],[],[]
for i in range(len(expression)):
v=expression[i]
if v.isalpha():
cur=[c+v for c in cur or ['']]
elif v=='{':
stack.append(res)
stack.append(cur)
res,cur=[],[]
elif v=='}':
pre=stack.pop()
preRes=stack.pop()
cur=[p+c for c in res+cur for p in pre or ['']]
res=preRes
elif v==',':
res+=cur
cur=[]
return sorted(set(res+cur))