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:
DFS(string s, int left, int right)
{
if(left + right == n * ){
res.push_back(s);
return;
}
if(left == right){
s += '(';
DFS(s, left+, right);
}else if(left > right){
if(left < n){
DFS(s+'(', left+, right);
}
DFS(s+')', left, right +);
}
}
vector<string> generateParenthesis(int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
res.clear();
this->n = n;
string s = "";
DFS(s, , );
return res;
}
private:
vector<string> res;
int n;
};

LeetCode_Generate Parentheses的更多相关文章

  1. [LeetCode] Remove Invalid Parentheses 移除非法括号

    Remove the minimum number of invalid parentheses in order to make the input string valid. Return all ...

  2. [LeetCode] Different Ways to Add Parentheses 添加括号的不同方式

    Given a string of numbers and operators, return all possible results from computing all the differen ...

  3. [LeetCode] Longest Valid Parentheses 最长有效括号

    Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...

  4. [LeetCode] Generate Parentheses 生成括号

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

  5. [LeetCode] Valid Parentheses 验证括号

    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...

  6. LeetCode 22. Generate Parentheses

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

  7. 【leetcode】Generate Parentheses

    题目简述: Given n pairs of parentheses, write a function to generate all combinations of well-formed par ...

  8. No.022:Generate Parentheses

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

  9. 【LeetCode】241. Different Ways to Add Parentheses

    Different Ways to Add Parentheses Given a string of numbers and operators, return all possible resul ...

随机推荐

  1. layer iframe层的使用,传参

    父层 <div class="col-xs-4 text-left" style="padding-left: 50px;"><button ...

  2. .net连接oracle(无客户端)

    使用DDTek.Oracle.dll可以在没有安装oracle客户端的情况下连接远程的oracle. string _conString = "Host=192.168.1.1;Port=1 ...

  3. PHPSTORM实用快捷键

    alt + F7 find usages 功能,可以很方便的找到函数在哪里调用了 Ctrl + E 可查看最近打开文件或项目 项目名右键选择"Local History | Show His ...

  4. 基于live555的视频直播 DM368IPNC RTSP分析

    因需要,从个人的理解顺序和需求角度对live555的分析与开发整理,包含RTSP Server与RTSP Client.如何直播H.264流与JPEG流等,均进行了探讨,对live555的初学者有一定 ...

  5. Guzzle php resetful webservice farmework

    Guzzle is a PHP HTTP client that makes it easy to work with HTTP/1.1 and takes the pain out of consu ...

  6. 【Android】Activity的菜单机制和方法解析

    Activity有一套机制来实现对菜单的管理,方法如下: 1. 初始化菜单 public boolean onCreateOptionsMenu(Menu menu) 此方法用于初始化菜单,其中men ...

  7. 学习设计模式--观察者模式(C++)

    1. 说说简单的函数回调 首先说说一种简单的函数回调机制(一种通过获取对象的指针来进行函数的调用方法)以下是代码演示--- 这是观察者(被回调)部分: class Observer { public: ...

  8. Tomcat全攻略

    内容: 一:简单介绍 二:安装及配置 三:应用 四:综述 參考资料 关于作者 相关内容: TCP/IP 介绍 TCP/IP 介绍 !== End Related dW Content Area --& ...

  9. 初探R语言——R语言笔记

    R语言使用 <-  赋值 # 作为注释符号 c()函数用于作为向量赋值,例如age<-c(1,2,3,4,5) mean()用于求向量的平均值 sd()求向量的标准差 cor(a,b)求a ...

  10. jquery之营销系统

    // //////////////////////////优惠券开始//////////////////////////// // 给附加条件选择框添加事件 function inputFuJia() ...