#
#
# @param n int整型
# @return string字符串一维数组
#
class Solution:
def generateParenthesis(self , n ):
# write code here
res = []#保存对象
cur_str = ''#储存括号
def dfs(cur_str, left, right): #左括号或者右括号还可以使用的个数
if left == 0 and right == 0:
res.append(cur_str)
return
if right < left: #生成括号的过程中,右括号使用的个数是不能多于左括号使用的个数的 return if left > 0:
dfs(cur_str + ')', left - 1, right)
if right > 0:
dfs(cur_str + '(', left, right - 1)
dfs(cur_str, n, n)
return res