# 括号生成

<p>数字 <code>n</code> 代表生成括号的对数，请你设计一个函数，用于能够生成所有可能的并且 <strong>有效的 </strong>括号组合。</p><p> </p><p><strong>示例 1：</strong></p><pre><strong>输入：</strong>n = 3<strong><br />输出：</strong>["((()))","(()())","(())()","()(())","()()()"]</pre><p><strong>示例 2：</strong></p><pre><strong>输入：</strong>n = 1<strong><br />输出：</strong>["()"]</pre><p> </p><p><strong>提示：</strong></p><ul>	<li><code>1 <= n <= 8</code></li></ul>

## template

```python
from typing import List
class Solution:
	def generateParenthesis(self, n: int) -> List[str]:
		def gen(p, lc, rc, r, n):
			if lc > n:
				return
			if lc == n and rc == n:
				r.append(''.join(p))
			p.append('(')
			lc += 1
			gen(p, lc, rc, r, n)
			p.pop()
			lc -= 1
			if lc > rc:
				p.append(')')
				rc += 1
				gen(p, lc, rc, r, n)
				p.pop()
				rc -= 1
		results = []
		gen([], 0, 0, results, n)
		return results
# %%
s = Solution()
print(s.generateParenthesis(n = 3))
```

## 答案

```python

```

## 选项

### A

```python

```

### B

```python

```

### C

```python

```