博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
22. 括号生成
阅读量:4028 次
发布时间:2019-05-24

本文共 661 字,大约阅读时间需要 2 分钟。

给出 n 代表生成括号的对数,请你写出一个函数,使其能够生成所有可能的并且有效的括号组合。

例如,给出 = 3,生成结果为

 

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

方法1:深搜:

class Solution {public:    void dfs(int n, vector
&re, string temp, int l, int r){ if(temp.size()==2*n){ re.push_back(temp); return; } if(l
generateParenthesis(int n) { vector
re; if(n==0) return re; dfs(n, re, "", 0, 0); return re; }};

方法2:迭代

class Solution {public:    vector
generateParenthesis(int n) { vector
re={""}; for(int i=0; i
temp; for(int j=0; j

 

转载地址:http://shabi.baihongyu.com/

你可能感兴趣的文章
ubuntu下SVN服务器安装配置
查看>>
MPMoviePlayerViewController和MPMoviePlayerController的使用
查看>>
CocoaPods实践之制作篇
查看>>
[Mac]Mac 操作系统 常见技巧
查看>>
苹果Swift编程语言入门教程【中文版】
查看>>
捕鱼忍者(ninja fishing)之游戏指南+游戏攻略+游戏体验
查看>>
iphone开发基础之objective-c学习
查看>>
iphone开发之SDK研究(待续)
查看>>
计算机网络复习要点
查看>>
Variable property attributes or Modifiers in iOS
查看>>
NSNotificationCenter 用法总结
查看>>
C primer plus 基础总结(一)
查看>>
剑指offer算法题分析与整理(一)
查看>>
剑指offer算法题分析与整理(三)
查看>>
部分笔试算法题整理
查看>>
Ubuntu 13.10使用fcitx输入法
查看>>
pidgin-lwqq 安装
查看>>
mint/ubuntu安装搜狗输入法
查看>>
C++动态申请数组和参数传递问题
查看>>
opencv学习——在MFC中读取和显示图像
查看>>