# 题目描述

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:
“((()))”, “(()())”, “(())()”, “()(())”, “()()()”

# 题目解答

#### 代码实现

public class Solution {

/**
* n个左括号 ， n个右括号
* 先放置左括号，然后再放置右括号
* 递归的解决
*/
public List<String> generateParenthesis(int n){

List<String> ret = new ArrayList<>();
parenthesesByRegression(ret, n, n, "");
return ret;
}

public void parenthesesByRegression(List<String> ret, int left, int right, String temp){

if(left == 0 && right ==0)
if(left > 0)
parenthesesByRegression(ret, left-1, right, temp+"(");
if(right > left)
parenthesesByRegression(ret, left, right-1, temp+")");
}
}

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

2015-08-24 11:29:56

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

2014-04-17 11:11:41

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

2015-05-10 21:11:15

#### leetcode之 Generate Parentheses

2013-10-26 23:19:18

#### LeetCode Generate Parentheses 深度分析理解

2013-11-26 08:05:53

#### LeetCode（22）Generate Parentheses

2015-09-26 19:57:28

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

2015-07-06 22:11:08

#### 【LeetCode】Generate Parentheses 解题报告

2014-10-16 15:26:03

#### 【LeetCode-面试算法经典-Java实现】【022-Generate Parentheses（生成括号）】

2015-07-23 07:52:20

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

2015-01-31 13:08:39

## 不良信息举报

Generate Parentheses