class Solution: def generateParenthesis(self, n: int) -> List[str]: if n==1: return ['()'] if not n: return None stack,res,l,r=[],[],[],[] for _ in range(n): l.append('(') r.append(')') def dfs(l,r): if not l and not r: res.append(''.join(i for i in stack)) return if l: stack.append(l.pop()) dfs(l,r) l.append(stack.pop()) if r and len(l)!=len(r): stack.append(r.pop()) dfs(l,r) r.append(stack.pop()) print(r) dfs(l,r) return res
标签:return,22,res,pop,stack,dfs,题库,LeetCode,append From: https://www.cnblogs.com/tanyuanqing/p/17764379.html