-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm1087 v1 sort after combinations.py
37 lines (33 loc) · 1.13 KB
/
m1087 v1 sort after combinations.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
28
29
30
31
32
33
34
35
36
37
class Solution:
def expand(self, s: str) -> List[str]:
outputs = []
currentlyInBrace = False
for c in s :
if not currentlyInBrace :
if c == '{' :
currentlyInBrace = True
outputs.append([])
else:
outputs.append(c)
else :
if c == '}' :
currentlyInBrace = False
elif c != ',' :
outputs[-1].append(c)
outputStrings = []
helperOutput = []
def helper(currIndx: int) -> None :
if currIndx >= len(outputs) :
outputStrings.append(''.join(helperOutput))
return
if isinstance(outputs[currIndx], str) :
helperOutput.append(outputs[currIndx])
helper(currIndx + 1)
helperOutput.pop()
else :
for c in outputs[currIndx] :
helperOutput.append(c)
helper(currIndx + 1)
helperOutput.pop()
helper(0)
return sorted(outputStrings)