当前位置:网站首页>【Hot100】22. bracket-generating
【Hot100】22. bracket-generating
2022-07-02 19:51:00 【Wang Liuliu's it daily】
22. Bracket generation
Medium question
Numbers n Represents the logarithm of the generated bracket , Please design a function , Used to be able to generate all possible and Effective Bracket combination .
Reference resources :https://leetcode.cn/problems/generate-parentheses/solution/zui-jian-dan-yi-dong-de-dong-tai-gui-hua-bu-lun-da/
Dynamic programming
class Solution {
public List<String> generateParenthesis(int n) {
List<List<String>> res = new LinkedList<>();
res.add(new LinkedList<>(Arrays.asList("")));
res.add(new LinkedList<>(Arrays.asList("()")));
for (int i = 2; i <= n; i++) {
List<String> tmp = new LinkedList<>();
for (int j = 0; j < i; j++) {
List<String> str1 = res.get(j);
List<String> str2 = res.get(i - 1 - j);
for (String s1 : str1) {
for (String s2 : str2) {
String str = "(" + s1 + ")" + s2;
tmp.add(str);
}
}
}
res.add(tmp);
}
return res.get(n);
}
}
边栏推荐
- Detailed explanation of VBScript (I)
- KT148A语音芯片使用说明、硬件、以及协议、以及常见问题,和参考代码
- AcWing 383. Sightseeing problem solution (shortest circuit)
- Set up sentinel mode. Reids and redis leave the sentinel cluster from the node
- Postman download and installation
- AcWing 343. Sorting problem solution (Floyd property realizes transitive closure)
- AcWing 340. 通信线路 题解(二分+双端队列BFS求最短路)
- c语言里怎么设立优先级,细说C语言优先级
- Codeworks round 802 (Div. 2) pure supplementary questions
- Motivation! Big Liangshan boy a remporté le prix Zhibo! Un article de remerciement pour les internautes qui pleurent
猜你喜欢

程序猿入门攻略(十二)——数据的存储

HDL design peripheral tools to reduce errors and help you take off!

Génération automatique de fichiers d'annotation d'images vgg

SQLite 3.39.0 release supports right external connection and all external connection

Automatically generate VGg image annotation file

SQLite 3.39.0 发布,支持右外连接和全外连接

Dictionaries

Motivation! Big Liangshan boy a remporté le prix Zhibo! Un article de remerciement pour les internautes qui pleurent

良心总结!Jupyter Notebook 从小白到高手,保姆教程来了!

Idea editor removes SQL statement background color SQL statement warning no data sources are configured to run this SQL And SQL dialect is not config
随机推荐
AcWing 1131. 拯救大兵瑞恩 题解(最短路)
分享几个图床网址,便于大家分享图片
AcWing 1135. 新年好 题解(最短路+搜索)
基于SSM实现网上购物商城系统
解决方案:VS2017 无法打开源文件 stdio.h main.h 等头文件[通俗易懂]
程序猿入门攻略(十二)——数据的存储
LeetCode 0871. Minimum refueling times - similar to poj2431 jungle adventure
AcWing 1134. Shortest circuit counting problem solution (shortest circuit)
Py之interpret:interpret的简介、安装、案例应用之详细攻略
Windows2008r2 installing php7.4.30 requires localsystem to start the application pool, otherwise 500 error fastcgi process exits unexpectedly
ShardingSphere-JDBC5.1.2版本关于SELECT LAST_INSERT_ID()本人发现还是存在路由问题
Zabbix5 client installation and configuration
GCC: Graph Contrastive Coding for Graph Neural NetworkPre-Training
Postman download and installation
Notes on hardware design of kt148a voice chip IC
AcWing 341. 最优贸易 题解 (最短路、dp)
开始练习书法
JS how to get integer
sql-labs
函数高阶-柯里化实现