Generate Parentheses
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:
"((()))", "(()())", "(())()", "()(())", "()()()"
思路:
左右括号总数相同,且在填充时左括号的个数始终要大于等于右括号的个数。据此递归生成所有的括号对。
题解:
class Solution {
public:
vector<string> result;
void generate_string(const string str, int lpnum, int rpnum)
{
if (lpnum == 0 &......
阅读全文