LeetCode_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:
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的更多相关文章
- [LeetCode] Remove Invalid Parentheses 移除非法括号
Remove the minimum number of invalid parentheses in order to make the input string valid. Return all ...
- [LeetCode] Different Ways to Add Parentheses 添加括号的不同方式
Given a string of numbers and operators, return all possible results from computing all the differen ...
- [LeetCode] Longest Valid Parentheses 最长有效括号
Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...
- [LeetCode] Generate Parentheses 生成括号
Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...
- [LeetCode] Valid Parentheses 验证括号
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- LeetCode 22. Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...
- 【leetcode】Generate Parentheses
题目简述: Given n pairs of parentheses, write a function to generate all combinations of well-formed par ...
- No.022:Generate Parentheses
问题: Given n pairs of parentheses, write a function to generate all combinations of well-formed paren ...
- 【LeetCode】241. Different Ways to Add Parentheses
Different Ways to Add Parentheses Given a string of numbers and operators, return all possible resul ...
随机推荐
- buffer busy wait
什么是buffer busy wait? A session that reads or modifies a buffer in the SGA must first acquire the cac ...
- cf500B New Year Permutation
B. New Year Permutation time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- FZU 11月月赛D题:双向搜索+二分
/* 双向搜索感觉是个不错的技巧啊 */ 题目大意: 有n的物品(n<=30),平均(两个人得到的物品差不能大于1)分给两个人,每个物品在每个人心目中的价值分别为(vi,wi) 问两人心目中的价 ...
- Junit 学习
一. 断言核心方法 示例代码: package com.test; import org.junit.Assert; import org.junit.Test; /** * @Title: test ...
- SQL VS NoSQL
(关系型与非关系型)数据库的区别: 关系型和非关系型数据库的主要差异是数据存储的方式 1.1 数据表 VS 数据集 关系型数据天然就是表格式的,因此存储在数据表的行和列中.数据表可以彼此关联协作存储, ...
- sqlite3经常使用命令&语法
http://blog.csdn.net/linchunhua/article/details/7184439 sqlite数据库仅仅用一个文件就ok,小巧方便,所以是一个很不错的嵌入式数据库,SQL ...
- 类型转换操作符static_cast、const_cast、dynamic_cast、reinterpret_cast
一.static_cast 对于类型转换,我们常常这么做: (type) expression 引进了static_cast类型转换操作符后,我们只需这样做: static_cast<type& ...
- Gradle的简介、安装与配置
Gradle介绍 Gradle是一个基于JVM的构建工具,它提供了: 像Ant一样,通用灵活的构建工具,对Ant的任务做了很好的集成 同Maven一样是基于约定的构建框架 强大的多工程构建支持.有广泛 ...
- 小学生之KTV项目文档(bdqn)
第一步:创建数据库连接方法和打开方法和关闭方法! 1 public class DBHelper 2 { 3 private string str = "server=.;database= ...
- ORACLE管理存储结构之物理机构+逻辑结构【weber出品】
一.数据库的存储结构有物理结构和逻辑结构组成的 物理结构:物理上,oracle是由一些操作系统文件组成的 SQL> select name from v$datafile; NAME ----- ...