Generate Parentheses
描述
Given n pairs of parentheses, write a function to generate all combinations of wellformed parentheses.
For example, given n = 3, a solution set is:
"((()))", "(()())", "(())()", "()(())", "()()()"
思路
该题目有一个规则是左括号个数得小于右括号个数,根据这个规则,可用通过动态规划来解决这个题目
代码
package com.lilei.myes.es.pack1107;public class generate_parentheses {public static void main(String[] args) {int num = 4;genp("", num, num);}public static void genp(String s, int left, int right) {if (left > 0 && right > 0) {if (left == right) {genp(s + "(", left - 1, right);} else if (left < right) {genp(s + "(", left - 1, right);genp(s + ")", left, right - 1);}} else {for (int i = 0; i < right; i++)s = s + ")";System.out.println(s);}}}
转载于:https://www.cnblogs.com/lilei2blog/p/7799586.html
Generate Parentheses相关推荐
- [leetcode] 22. Generate Parentheses
题目大意 https://leetcode.com/problems/generate-parentheses/description/ 22. Generate Parentheses Given ...
- [CareerCup] 9.6 Generate Parentheses 生成括号
9.6 Implement an algorithm to print all valid (e.g., properly opened and closed) combinations of n-p ...
- LeetCode算法入门- Generate Parentheses -day16
LeetCode算法入门- Generate Parentheses -day16 题目描述 Given n pairs of parentheses, write a function to gen ...
- LeetCode Generate Parentheses
原题链接在这里:https://leetcode.com/problems/generate-parentheses/ 题目: Given n pairs of parentheses, write ...
- 【LeetCode每天一题】Generate Parentheses(创造有效的括弧)
Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...
- 【LeetCode从零单排】No22.Generate Parentheses
题目 Given n pairs of parentheses, write a function to generate all combinations of well-formed parent ...
- 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 parenthes ...
- [LeetCode] #22 Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...
最新文章
- LINUX驱动注册过程失败处理不当引起的恶果
- 【转】排除被冲销的物料凭证
- 以用户体验为导向的设计表现
- 直播实录 | 哈工大博士生周青宇:从编码器与解码器端改进生成式句子摘要
- boost::fusion::unfused_typed用法的测试程序
- 细数家庭安防五大乱象 何时能步入正轨
- python 三元运算、列表推倒式、字典推倒式、生成器生成式
- 51nod 博弈论水题
- mysql数据库p_PbootCMS Sqlite数据库转Mysql数据库教程
- 基于proteus的一个微程序CPU
- 程序人生 | 文艺程序员使用代码发展诗歌
- 爬虫 爬取百思不得姐网站
- 即时通讯(WebSocket、Socket IO)
- 二阶系统响应指标图_二阶系统的脉冲响应.ppt
- eap wifi 证书_如何以编程方式在Android中安装CA证书(用于EAP WiFi配置)?
- 【C++实现】编译原理 免考小队 NFA转换为等价的DFA
- 美国军方又出黑科技,实现用意念控制无人机
- linux机器上crontab定时任务将日志输出到以日期命名的log文件
- sizeof c语言是什么表达式,C 语言 sizeof() 运算符
- JS练习之鼠标经过切换图片
热门文章
- 美团外卖骑手背后的AI技术
- redhat7配置本地源
- threadlocal使用_Java多线程数据共享神器ThreadLocal
- PHP 模拟真实ip,PHP实现-获取用户的真实IP
- anaconda3安装_Anaconda3软件与安装教程
- mysql如何定义消耗资源多的sql语句_如何查找消耗资源较大的SQL
- hust1346(两个线段的最近距离和最小距离)
- php.ini文件可以复制吗,php安装完成以后要复制php.ini文件
- 2021-03-01 英文写作中的“许多”
- Webshell免杀绕过waf