题目:

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:

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

思路:卡塔兰数。

c++实现:

class Solution {
public:vector<string> generateParenthesis(int n) {vector<string> res;string s = "";if(n <= 0){return res;}generate(n, n, s, res);return res;}void generate(int l, int r, string s, vector < string > &res){if(r < l)return;if(l == 0 && r == 0){res.push_back(s);}if(l>0)generate(l-1, r, s+"(", res);if(r>0)generate(l, r-1, s+")", res);}
};

  

转载于:https://www.cnblogs.com/zhutianpeng/p/4282753.html

[leetcode]Generate Parentheses相关推荐

  1. LeetCode Generate Parentheses

    原题链接在这里:https://leetcode.com/problems/generate-parentheses/ 题目: Given n pairs of parentheses, write ...

  2. [LeetCode] Generate Parentheses

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

  3. LeetCode:Generate Parentheses

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

  4. [leetcode] 22. Generate Parentheses

    题目大意 https://leetcode.com/problems/generate-parentheses/description/ 22. Generate Parentheses Given ...

  5. LeetCode算法入门- Generate Parentheses -day16

    LeetCode算法入门- Generate Parentheses -day16 题目描述 Given n pairs of parentheses, write a function to gen ...

  6. [CareerCup] 9.6 Generate Parentheses 生成括号

    9.6 Implement an algorithm to print all valid (e.g., properly opened and closed) combinations of n-p ...

  7. 【LeetCode每天一题】Generate Parentheses(创造有效的括弧)

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

  8. 【LeetCode从零单排】No22.Generate Parentheses

    题目 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. JAVA 多用户商城系统b2b2c-Spring Cloud常见问题与总结(一)
  2. 异步IO一定更好吗?
  3. php padright,[扩展推荐] PHP 字符串操作类 Twine
  4. Visual Studio 2019 + Visual C++——创建Visual C++ Hello World! 程序
  5. c语言中日期间的天数怎么计算,关于计算两个日期间天数的代码,大家来看看...
  6. 计算机黑屏策略,小黑w7系统诊断策略服务已被禁用的还原教程
  7. 操作系统课设之Windows 的互斥与同步
  8. Cards and Joy CodeForces - 999F (贪心+set)
  9. 从零开始学做微信小程序,看这些就够了!
  10. OpenGL基础30:模板测试
  11. [转载] [转载] python set集合如何有序输出_python set集合的用法
  12. openwrt监控linux,openwrt linux portal 实现 支持 https 支持基于时长和流量控制
  13. python读取文件中的内容_python逐行读取文件内容的三种方法
  14. oracle中存储函数,oracle中存储函数与存储过程的区别介绍
  15. 竖着的seekbar_自定义竖着的SeekBar | 学步园
  16. 一个高手的趋势交易、量化交易系统思路
  17. Minimum Class Confusion for Versatile Domain Adaptation
  18. 谈论机器学习中,哪种学习算法更好有意义吗?
  19. CSS让同一行的图片和文字垂直居中对齐
  20. 连咖啡:新零售时代中的娱乐“生意经” | 一点财经

热门文章

  1. Delphi 自带的 Base64 编解码函数
  2. UIEdgeInsets
  3. Linq之ToDictionaryTSource, TKey, TElement的写法
  4. 利用微信的weui框架上传、预览和删除图片
  5. SPI和RAM IP核
  6. Unity3D手机斗地主游戏开发实战(02)_叫地主功能实现
  7. lrzsz   linux与windows互传
  8. 轻量级数据库中间件利器Sharding-JDBC深度解析(有彩蛋)
  9. C#实现简单的 Ping 的功能,用于测试网络是否已经联通
  10. linux命令行快捷键