当前位置:网站首页>【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);
}
}
边栏推荐
- Solution: vs2017 cannot open the source file stdio h main. H header document [easy to understand]
- Detailed explanation of VBScript (I)
- Is there any security guarantee for the ranking of stock and securities companies
- Postman下载安装
- 数据湖(十二):Spark3.1.2与Iceberg0.12.1整合
- pxe装机「建议收藏」
- 为什么我对流程情有独钟?
- 4274. Suffix expression - binary expression tree
- AcWing 1127. 香甜的黄油 题解(最短路—spfa)
- Correspondence between pytoch version, CUDA version and graphics card driver version
猜你喜欢
Bubble sort array
Educational codeforces round 129 (rated for Div. 2) supplementary problem solution
KT148A语音芯片ic的开发常见问题以及描述
Set up sentinel mode. Reids and redis leave the sentinel cluster from the node
rxjs Observable 自定义 Operator 的开发技巧
B端电商-订单逆向流程
Introduction to program ape (XII) -- data storage
Istio部署:快速上手微服务,
AcWing 1126. 最小花费 题解(最短路—dijkstra)
Motivation! Big Liangshan boy a remporté le prix Zhibo! Un article de remerciement pour les internautes qui pleurent
随机推荐
Workplace four quadrant rule: time management four quadrant and workplace communication four quadrant "suggestions collection"
B端电商-订单逆向流程
Istio1.12:安装和快速入门
Overview of browser caching mechanism
Common problems and description of kt148a voice chip IC development
Motivation! Big Liangshan boy a remporté le prix Zhibo! Un article de remerciement pour les internautes qui pleurent
Py's interpret: a detailed introduction to interpret, installation, and case application
开始练习书法
451-memcpy、memmove、memset的实现
Kt148a voice chip IC user end self replacement voice method, upper computer
RPD product: super power squad nanny strategy
rxjs Observable 自定义 Operator 的开发技巧
多端小程序开发有什么好处?覆盖百度小程序抖音小程序微信小程序开发,抢占多平台流量红利
AcWing 342. Road and route problem solving (shortest path, topological sorting)
中缀表达式转换为后缀表达式(C语言代码+详解)
Build a master-slave mode cluster redis
Detailed explanation of VBScript (I)
自動生成VGG圖像注釋文件
安装单机redis详细教程
Zabbix5 client installation and configuration