Generate Parentheses

Description

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

For example, given n = 3, a solution set is:

[
  "((()))",
  "(()())",
  "(())()",
  "()(())",
  "()()()"
]

给出n组括号,生成所有正确的匹配组合

Solution

本题不贴代码。

思路是生成过程中,保持右括号数量不超过左括号数量即可。