Leetcode: Generate Parentheses
2013-10-17 06:57
330 查看
http://oj.leetcode.com/problems/generate-parentheses/
// Interesting questions // It is very easy to generate duplicated result with normal dp // The core idea is that from the start to the end of the string, // we need to keep the property that cnt("(") is more than or equal to cnt(")") class Solution { public: void Generate(int left, int right, string current, vector<string> &res){ if(left==0&&right==0) res.push_back(current); if(left>0) Generate(left-1,right,current+"(",res); if(right>left) Generate(left,right-1,current+")",res); } vector<string> generateParenthesis(int n) { vector<string> res; Generate(n,n,"",res); return res; } };
相关文章推荐
- 第19章 导航和布局设计模式
- 百度BAE数据库连接问题
- 百度BAE数据库连接问题
- sizeof运算符的学习笔记
- 多列分区
- g77 arm 编译器
- ORA-01791:不是 SELECTed 表达式
- PHP 中变量的间接引用
- Android基站定位
- JavaScript<四>_DOM
- 线程并发库<二>_线程池
- Combination Sum
- struts2的工作流程(易懂版)
- 白首方恨读书迟
- 解决EF一对一或多对一的删除
- java 关于操作oracle的clob类型
- 有关 C 指针的个人另类概念(1)
- Java is Pass-by-Value, Dammit!
- linux服务器安全加固shell脚本
- nodejs广播