class Solution:
def __init__(self):
self.ans = list()
def generateParenthesis(self, n: int) -> List[str]:
self.DFS(n-1, 1, '(')
return self.ans
def DFS(self, n, stacked, strings):
if n == 0:
self.ans.append(strings + ')' * stacked)
return
# '(' 추가
self.DFS(n - 1, stacked + 1, strings + '(')
# ')' 추가
if stacked > 0:
self.DFS(n, stacked - 1, strings + ')')