原题地址:https://leetcode.com/problems/generate-parentheses/

解决方法:回溯法

class Solution {
private:
vector<string> coll;
void helper(string s, int left, int right){
if(left > right || left < || right < )
return;
if( == left && == right){
coll.push_back(s);
return;
}
string lString = s, rString = s;
helper(lString += '(', left - , right);
helper(rString += ')', left, right - );
}
public:
vector<string> generateParenthesis(int n) {
string s;
helper(s, n, n);
return coll;
}
};

LeetCode题目:Generate Parentheses的更多相关文章

  1. 【题解】【排列组合】【回溯】【Leetcode】Generate Parentheses

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

  2. LeetCode 022 Generate Parentheses

    题目描述:Generate Parentheses Given n pairs of parentheses, write a function to generate all combination ...

  3. [LeetCode] 22. Generate Parentheses 生成括号

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

  4. 【leetcode】Generate Parentheses

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

  5. Java [leetcode 22]Generate Parentheses

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

  6. leetcode@ [22]Generate Parentheses (递归 + 卡特兰数)

    https://leetcode.com/problems/generate-parentheses/ Given n pairs of parentheses, write a function t ...

  7. leetcode之 Generate Parentheses

    题目:http://oj.leetcode.com/problems/generate-parentheses/ 描述:给定一个非负整数n,生成n对括号的所有合法排列. 解答: 该问题解的个数就是卡特 ...

  8. 蜗牛慢慢爬 LeetCode 22. Generate Parentheses [Difficulty: Medium]

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

  9. [LeetCode]22. Generate Parentheses括号生成

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

随机推荐

  1. Android NDK使用

    1. 介绍 这里主要想记录一下Android NDK开发C程序的使用方法 2. ndk下载 到google官网或者国内镜像网站下载android-ndk形如:  android-ndk-r<ve ...

  2. js比对一维数组全等的算法

    //辅助方法1,返回某个值在数组中的位置 Array.prototype.indexOf = function (e) { for (var i = 0, l = this.length; i < ...

  3. Java程序执行时间

    第一种是以毫秒为单位计算的.  Java代码  //伪代码 long startTime=System.currentTimeMillis();   //获取开始时间 doSomeThing();  ...

  4. AC日记——[SCOI2008] 着色方案 bzoj 1079

    1079 思路: dp: 我们如果dp方程为15维,每维记录颜色还有多少种: 不仅tle,mle,它还re: 所以,我们压缩一下dp方程: 方程有6维,第i维记录有多少种颜色还剩下i次: 最后还要记录 ...

  5. 51nod 1133 不重叠的线段【贪心/区间覆盖】

    1133 不重叠的线段 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题  收藏  关注 X轴上有N条线段,每条线段有1个起点S和终点E.最多能够选出多少条互不重叠的 ...

  6. bzoj3225 [Sdoi2008]立方体覆盖——扫描线

    3225: [Sdoi2008]立方体覆盖 Description A君近日为准备省队选拔,特意进行了数据结构的专项训练.训练过程中就遇到了“矩形面积并”这道经典问题,即:给出N个各边与坐标轴平行(垂 ...

  7. SPOJ705 SUBST1 - New Distinct Substrings(后缀数组)

    给一个字符串求有多少个不相同子串. 每一个子串一定都是某一个后缀的前缀.由此可以推断出总共有(1+n)*n/2个子串,那么下面的任务就是找这些子串中重复的子串. 在后缀数组中后缀都是排完序的,从sa[ ...

  8. 四. Java继承和多态9. 类与类之间的关系

    类与类之间最常见的关系主要有三种:依赖(uses-a).聚合(has-a)和继承(is-a). 下面以在线书店订单系统为例,来详细的讲述这三种关系的概念. 在线书店订单系统的主要功能是:注册用户可以登 ...

  9. HashMap源码-描述部分

    /** * Hash table based implementation of the <tt>Map</tt> interface. This * implementati ...

  10. Spcomm 属性详解

    http://wenku.baidu.com/link?url=w53wCrhi_E33atqp0joeG029YO3H2z4Xy101oGbKqhG9bfWJQHSmcMi4q7l6xrS424St ...