当前位置:网站首页>【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);
}
}
边栏推荐
- Automatically generate VGg image annotation file
- 4274. Suffix expression - binary expression tree
- NMF-matlab
- Use cheat engine to modify money, life and stars in Kingdom rush
- 有时候只查询一行语句,执行也慢
- SQLite 3.39.0 发布,支持右外连接和全外连接
- KS004 基于SSH通讯录系统设计与实现
- Workplace four quadrant rule: time management four quadrant and workplace communication four quadrant "suggestions collection"
- 解决方案:VS2017 无法打开源文件 stdio.h main.h 等头文件[通俗易懂]
- 蓝牙芯片ble是什么,以及该如何选型,后续技术发展的路径是什么
猜你喜欢

KT148A语音芯片使用说明、硬件、以及协议、以及常见问题,和参考代码
Bubble sort array

AcWing 342. 道路与航线 题解 (最短路、拓扑排序)

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

zabbix5客户端安装和配置

Set up sentinel mode. Reids and redis leave the sentinel cluster from the node

JASMINER X4 1U深度拆解,揭开高效省电背后的秘密

基于SSM实现网上购物商城系统

AcWing 903. Expensive bride price solution (the shortest path - building map, Dijkstra)

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
随机推荐
KT148A语音芯片ic的开发常见问题以及描述
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
Introduction to mongodb chapter 03 basic concepts of mongodb
[ERP software] what are the dangers of the secondary development of ERP system?
Postman下载安装
Detailed explanation of VBScript (I)
Set up sentinel mode. Reids and redis leave the sentinel cluster from the node
MySQL
AcWing 343. Sorting problem solution (Floyd property realizes transitive closure)
AcWing 1126. 最小花费 题解(最短路—dijkstra)
励志!大凉山小伙全奖直博!论文致谢看哭网友
《重构:改善既有代码的设计》读书笔记(下)
Istio部署:快速上手微服务,
AcWing 1127. 香甜的黄油 题解(最短路—spfa)
c语言里怎么设立优先级,细说C语言优先级
Kt148a voice chip instructions, hardware, protocols, common problems, and reference codes
为什么我对流程情有独钟?
Solution: vs2017 cannot open the source file stdio h main. H header document [easy to understand]
Start practicing calligraphy
SQLite 3.39.0 release supports right external connection and all external connection