leetcode-algorithms-22 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:

[
"((()))",
"(()())",
"(())()",
"()(())",
"()()()"
]

解法

class Solution {
public:
vector<string> generateParenthesis(int n)
{
std::vector<std::string> result;
addParenth(result, "", n, 0); return result;
} void addParenth(std::vector<std::string> &v, std::string str, int n, int m)
{
if(n==0 && m==0)
{
v.push_back(str);
return;
} if(m > 0)
addParenth(v, str+")", n, m-1);
if(n > 0)
addParenth(v, str+"(", n-1, m+1);
}
};

链接: leetcode-algorithms 目录

leetcode-algorithms-22 Generate Parentheses的更多相关文章

  1. [Leetcode][Python]22: Generate Parentheses

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 22: Generate Parentheseshttps://oj.leet ...

  2. 【一天一道LeetCode】#22. Generate Parentheses

    一天一道LeetCode (一)题目 Given n pairs of parentheses, write a function to generate all combinations of we ...

  3. 【LeetCode】22. Generate Parentheses (2 solutions)

    Generate Parentheses Given n pairs of parentheses, write a function to generate all combinations of ...

  4. 【LeetCode】22. Generate Parentheses (I thought I know Python...)

    I thought I know Python... Actually , I know nothing... 这个题真想让人背下来啊,每一句都很帅!!! Given n pairs of paren ...

  5. 【LeetCode】22. Generate Parentheses 括号生成

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:括号, 括号生成,题解,leetcode, 力扣,Pyt ...

  6. LeetCode OJ 22. Generate Parentheses

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

  7. 【leetcode】22. Generate Parentheses

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

  8. LeetCode:22. Generate Parentheses(Medium)

    1. 原题链接 https://leetcode.com/problems/generate-parentheses/description/ 2. 题目要求 给出一个正整数n,请求出由n对合法的圆括 ...

  9. 22. Generate Parentheses(ML)

    22. Generate Parentheses . Generate Parentheses Given n pairs of parentheses, write a function to ge ...

  10. 刷题22. Generate Parentheses

    一.题目说明 这个题目是22. Generate Parentheses,简单来说,输入一个数字n,输出n对匹配的小括号. 简单考虑了一下,n=0,输出"";n=1,输出" ...

随机推荐

  1. [POJ 2386] Lake Counting(DFS)

    Lake Counting Description Due to recent rains, water has pooled in various places in Farmer John's f ...

  2. Docker run 出现问题如何调试?

    docker run -ti 3f5dd697cc83 /bin/bash #进入image的目录 ls -l #列出所有目录 dotnet run WestWin.Ads.Crawler.WebAp ...

  3. NPOI 导入Excel和读取Excel

    1.整个Excel表格叫做工作表:WorkBook(工作薄),包含的叫页(工作表):Sheet:行:Row:单元格Cell. 2.NPOI是POI的C#版本,NPOI的行和列的index都是从0开始 ...

  4. 不可改变性imutable

    不可改变性是指一些对象在被创建之后不会因为某些方式改变,特别是针对任何可以改变哈希对象的哈希值的方式. 两者相联系是因为哈希键值一定是不可改变的,所以它们对应的哈希键值也不改变. 如果允许它们改变,那 ...

  5. Django安装与创建项目

    下载 https://media.djangoproject.com/releases/1.11/Django-1.11.20.tar.gz 解压 tar -zvxf Django-1.11.20.t ...

  6. Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile

    完整的错误信息: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile ( ...

  7. C++.【转】C++数值类型与string的相互转换

    1.C++数值类型与string的相互转换 - JohnGu - 博客园.html(https://www.cnblogs.com/johngu/p/7878029.html) 2. 1.数值类型转换 ...

  8. [Android] for ArcFace Demo

    虹软人脸识别引擎Android的Demo演示,可以直接下载使用 下载地址 https://github.com/asdfqwrasdf/ArcFaceDemo 工程如何使用? 1.下载代码: git ...

  9. 牛客网NOIP赛前集训营-提高组(第七场)C 洞穴

    洞穴 思路: 矩阵乘法 由于只需要知道 A ^ l 的 第a行第b个元素 所以我们每次在做矩阵乘法时只需要算第a行就可以了 还要像矩阵快速幂一样预处理A ^ (1<<d) 代码: #pra ...

  10. AtCoder Regular Contest 094 D Worst Case

    Worst Case 思路: 使 a <= b 当 a == b 时 或者 a == b - 1 时,答案显然为 2 * (a - 1) 否则找到最大的 c ,使得 c * c < a * ...