class Solution(object):
def generateParenthesis(self, n):
"""
:type n: int
:rtype: List[str]
"""
def dfs(left, right):
if right == n:
res.append(''.join(path))
if left < n:
path.append("(")
dfs(left + 1, right)
del path[-1]
if right < left:
path.append(")")
dfs(left, right + 1)
del path[-1]
path = []
res = []
dfs(0, 0)
return res