# 【leetcode】Generate Parentheses

## 题目：

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

`"((()))", "(()())", "(())()", "()(())", "()()()"`

## 实现：

```  void dfs(vector<string> &re, string& cur_re, int unmatched_lefts, int added_lefts, int n)
{

if(unmatched_lefts == 0 && added_lefts == n)
{
re.push_back(cur_re);
}

if(unmatched_lefts > 0){//insert ')' is ok
cur_re.append(1, ')');
dfs(re, cur_re, unmatched_lefts - 1, added_lefts, n);
}

{
cur_re.append(1,'(');
dfs(re, cur_re, unmatched_lefts + 1, added_lefts + 1, n);
}
cur_re.pop_back();
}
vector<string> generateParenthesis(int n) {

vector<string> re;
if(n <= 0)
return re;
string one_solve;
one_solve.append(1, '(');
dfs(re, one_solve, 1, 1, n);
return re;
}```

【leetcode】Generate Parentheses,布布扣,bubuko.com

## 【LeetCode】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: "((()))", "(()())", "(())()", "()(())", "()()()" [思

## 【LeetCode】Generate Parentheses (2 solutions)

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

## 【Leetcode】Generate Parentheses in JAVA

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: "((()))", "(()())", "(())()", "()(())", "()()()" 用dfs思想做

## 【leetcode】 Generate Parentheses (middle)☆

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: "((()))", "(()())", "(())()", "()(())", "()()()" 思路:产生所有

## 【leetcode】Valid Parentheses

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "()" and "()[]{}" are all valid but "(]" and "([)]"

## 【LeetCode】- Valid Parentheses（有效的括号）

[ 问题: ] Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. 直译:给定一个字符串,该串包含字符'(', ')', '{', '}', '[', ']', 请判断它是不是有效的 The brackets must close in the correct order, "()" and "

## 【LeetCode】字符串 string（共112题）

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica } [3]Longest Substring Without Repeating Characters [5]Longest Palindromic Substring [6]ZigZag Conversion [8]String to Integer (atoi) [10]Regular Expression Matching [12]Integer to Roman

## 【LeetCode】回溯法 backtracking（共39题）

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica } [10]Regular Expression Matching [17]Letter Combinations of a Phone Number [22]Generate Parentheses (2019年2月13日) 给了一个N,生成N对括号的所有情况的字符串. n = 3 [ "((()))", "(()())", "(