当前位置:网站首页>【Hot100】22. 括号生成
【Hot100】22. 括号生成
2022-07-02 18:54:00 【王六六的IT日常】
22. 括号生成
中等题
数字 n 代表生成括号的对数,请你设计一个函数,用于能够生成所有可能的并且 有效的 括号组合。
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);
}
}
边栏推荐
- R语言使用econocharts包创建微观经济或宏观经济图、indifference函数可视化无差异曲线(indifference curve)
- AcWing 341. Optimal trade solution (shortest path, DP)
- KS004 基于SSH通讯录系统设计与实现
- AcWing 340. Solution to communication line problem (binary + double ended queue BFS for the shortest circuit)
- Solution: vs2017 cannot open the source file stdio h main. H header document [easy to understand]
- 职场四象限法则:时间管理四象限与职场沟通四象限「建议收藏」
- Istio1.12: installation and quick start
- 良心总结!Jupyter Notebook 从小白到高手,保姆教程来了!
- AcWing 1137. Select the best line solution (the shortest circuit)
- What are the benefits of multi terminal applet development? Covering Baidu applet, Tiktok applet, wechat applet development, and seizing the multi platform traffic dividend
猜你喜欢

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 1126. Minimum cost solution (shortest path Dijkstra)

Registration opportunity of autowiredannotationbeanpostprocessor under annotation development mode

zabbix5客户端安装和配置

自动生成VGG图像注释文件

Self-Improvement! Daliangshan boys all award Zhibo! Thank you for your paper

《MongoDB入门教程》第03篇 MongoDB基本概念

SQLite 3.39.0 release supports right external connection and all external connection

Introduction to mongodb chapter 03 basic concepts of mongodb

AcWing 342. Road and route problem solving (shortest path, topological sorting)
随机推荐
Py之interpret:interpret的简介、安装、案例应用之详细攻略
From 20s to 500ms, I used these three methods
Is there any security guarantee for the ranking of stock and securities companies
Correspondence between pytoch version, CUDA version and graphics card driver version
JS如何取整数
After writing 100000 lines of code, I sent a long article roast rust
蓝牙芯片ble是什么,以及该如何选型,后续技术发展的路径是什么
程序猿入门攻略(十二)——数据的存储
AcWing 1128. 信使 题解(最短路—Floyd)
AcWing 343. 排序 题解(floyd性质实现传递闭包)
KT148A语音芯片ic的用户端自己更换语音的方法,上位机
Postman下载安装
HDL design peripheral tools to reduce errors and help you take off!
One side is volume, the other side is layoff. There are a lot of layoffs in byte commercialization department. What do you think of this wave?
Codeworks round 802 (Div. 2) pure supplementary questions
AcWing 343. Sorting problem solution (Floyd property realizes transitive closure)
NMF-matlab
有时候只查询一行语句,执行也慢
Refactoring: improving the design of existing code (Part 1)
AcWing 1125. 牛的旅行 题解(最短路、直径)