###### LeetCode22: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:

“((()))”, “(()())”, “(())()”, “()(())”, “()()()”

left：表示剩余左括号的数目
right：表示剩余右括号的数目

1. 当left=0&&right=0时表示找到一条路径
2. 当left!=0时可以向左子树伸展
3. 当right!=0&&left< right时可以向右子树伸展

runtime:0ms

class Solution {
public:
vector<string> generateParenthesis(int n) {
vector<string> result;
string path;
helper(n,n,path,result);
return result;
}

void helper(int left,int right,string path,vector<string> & result)
{
if(left==0&&right==0)
{
result.push_back(path);
return ;
}
if(left!=0)
helper(left-1,right,path+"(",result);
if(right!=0&&left<right)
helper(left,right-1,path+")",result);
}

};

#### LeetCode 22：Generate Parentheses的递归，回溯两种解法

2015-08-24 11:29:56

#### LeetCode 22 — Generate Parentheses（C++ Java Python）

2014-04-17 11:11:41

#### Leetcode22-Generate Parentheses 之深入理解回溯算法

2018-03-12 14:48:05

#### leetCode 22.Generate Parentheses (生成括号) 解题思路和方法

2015-07-06 22:11:08

#### leetcode-java-22. Generate Parentheses

2016-06-09 21:28:09

#### LeetCode --- 22. Generate Parentheses

2015-01-31 13:08:39

#### leetcode 22. Generate Parentheses-回溯|递归

2016-05-28 16:27:19

#### LeetCode（22）Generate Parentheses

2015-09-26 19:57:28

#### LeetCode 22 Generate Parentheses (C,C++,Java,Python)

2015-05-10 21:11:15

#### (Java)LeetCode-22. Generate Parentheses

2016-06-01 16:19:45

## 不良信息举报

LeetCode22:Generate Parentheses