当前位置:网站首页>【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);
}
}
边栏推荐
- 使用IDM下载百度网盘的文件(亲测有用)[通俗易懂]
- 安装单机redis详细教程
- 【NLP】一文详解生成式文本摘要经典论文Pointer-Generator
- Istio部署:快速上手微服务,
- Educational codeforces round 129 (rated for Div. 2) supplementary problem solution
- From 20s to 500ms, I used these three methods
- 浏览器缓存机制概述
- Shardingsphere jdbc5.1.2 about select last_ INSERT_ ID () I found that there was still a routing problem
- checklistbox控件用法总结
- Educational Codeforces Round 129 (Rated for Div. 2) 补题题解
猜你喜欢

Istio1.12:安装和快速入门

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

AcWing 903. 昂贵的聘礼 题解(最短路—建图、dijkstra)

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

自動生成VGG圖像注釋文件

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

《重构:改善既有代码的设计》读书笔记(下)

API文档工具knife4j使用详解

sql-labs

HDL design peripheral tools to reduce errors and help you take off!
随机推荐
B端电商-订单逆向流程
思考变量引起的巨大变化
rxjs Observable 自定义 Operator 的开发技巧
Registration opportunity of autowiredannotationbeanpostprocessor in XML development mode
MySQL table historical data cleaning summary
pxe装机「建议收藏」
AcWing 1129. Heat wave solution (shortest path SPFA)
从20s优化到500ms,我用了这三招
Bubble sort array
在消费互联网时代,诞生了为数不多的头部平台的话
PXE installation "recommended collection"
CRM客户关系管理系统
checklistbox控件用法总结
定了,就是它!
451 implementation of memcpy, memmove and memset
AcWing 341. 最优贸易 题解 (最短路、dp)
Embedded (PLD) series, epf10k50rc240-3n programmable logic device
MySQL
Start practicing calligraphy
NMF-matlab