File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ def prettyPrint (l ):
2+ return ["" .join (e ) for e in l ]
3+
4+ def recursive_generation (c , start , end ):
5+ c = c .copy ()
6+
7+ if start >= end :
8+ return [c ]
9+
10+ c [start ] = "("
11+
12+ filled_lists = []
13+
14+ for i in range (int ((end - start ) / 2 )):
15+ c [start + 1 + i * 2 ] = ")"
16+
17+ bracket_lists = recursive_generation (c , start + 1 , start + 1 + i * 2 )
18+
19+ for bracket_list in bracket_lists :
20+ filled_lists += recursive_generation (bracket_list , start + 2 + i * 2 , end )
21+
22+ c [start + 1 + i * 2 ] = "."
23+
24+ return filled_lists
25+
26+
27+
28+ class Solution :
29+ def generateParenthesis (self , n : int ) -> List [str ]:
30+ # [(, 0, 0, 0, 0, 0]
31+
32+ # [(, ), 0, 0, 0, 0]
33+ # [(, 0, 0, ), 0, 0]
34+ # [(, 0, 0, 0, 0, )]
35+
36+
37+ return prettyPrint (recursive_generation (["." ] * n * 2 , 0 , n * 2 ))
You can’t perform that action at this time.
0 commit comments