当前位置:网站首页>【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);
}
}
边栏推荐
- JS how to get integer
- AcWing 181. Turnaround game solution (search ida* search)
- ShardingSphere-JDBC5.1.2版本关于SELECT LAST_INSERT_ID()本人发现还是存在路由问题
- KT148A语音芯片ic的用户端自己更换语音的方法,上位机
- 蓝牙芯片ble是什么,以及该如何选型,后续技术发展的路径是什么
- Motivation! Big Liangshan boy a remporté le prix Zhibo! Un article de remerciement pour les internautes qui pleurent
- AcWing 1129. 热浪 题解(最短路—spfa)
- Py's interpret: a detailed introduction to interpret, installation, and case application
- Istio deployment: quickly start microservices,
- Kt148a voice chip IC software reference code c language, first-line serial port
猜你喜欢
Refactoring: improving the design of existing code (Part 2)
程序猿入门攻略(十二)——数据的存储
AcWing 1126. 最小花费 题解(最短路—dijkstra)
Py's interpret: a detailed introduction to interpret, installation, and case application
Kt148a voice chip instructions, hardware, protocols, common problems, and reference codes
SQLite 3.39.0 release supports right external connection and all external connection
AcWing 342. 道路与航线 题解 (最短路、拓扑排序)
KT148A语音芯片使用说明、硬件、以及协议、以及常见问题,和参考代码
励志!大凉山小伙全奖直博!论文致谢看哭网友
Istio1.12: installation and quick start
随机推荐
Kt148a voice chip IC user end self replacement voice method, upper computer
What are the benefits of multi terminal applet development? Covering Baidu applet, Tiktok applet, wechat applet development, and seizing the multi platform traffic dividend
Is there any security guarantee for the ranking of stock and securities companies
在消费互联网时代,诞生了为数不多的头部平台的话
c语言里怎么设立优先级,细说C语言优先级
Use IDM to download Baidu online disk files (useful for personal testing) [easy to understand]
Implementation of online shopping mall system based on SSM
452-strcpy、strcat、strcmp、strstr、strchr的实现
攻防世界pwn题:Recho
勵志!大凉山小夥全獎直博!論文致謝看哭網友
zabbix5客户端安装和配置
GCC: Graph Contrastive Coding for Graph Neural NetworkPre-Training
Build a master-slave mode cluster redis
rxjs Observable 自定义 Operator 的开发技巧
AcWing 340. 通信线路 题解(二分+双端队列BFS求最短路)
Postman下载安装
良心总结!Jupyter Notebook 从小白到高手,保姆教程来了!
LeetCode 0871. Minimum refueling times - similar to poj2431 jungle adventure
Solution: vs2017 cannot open the source file stdio h main. H header document [easy to understand]
编写完10万行代码,我发了篇长文吐槽Rust