当前位置:网站首页>【leetcode】22. bracket-generating
【leetcode】22. bracket-generating
2022-07-06 03:56:00 【Chinese fir sauce_】
subject :
22. Bracket generation
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 .
Example 1:
Input :n = 3
Output :["((()))","(()())","(())()","()(())","()()()"]
Example 2:
Input :n = 1
Output :["()"]
Tips :
1 <= n <= 8
Depth-first traversal :
class Solution {
List<String> ans;
public List<String> generateParenthesis(int n) {
ans = new ArrayList<>();
search(0,0,n,0,"");
return ans;
}
void search(int ln,int rn,int n,int len,String cur){
if(len == n * 2){
ans.add(new String(cur));
return;
}
// The number of left parentheses is less than n
if(ln < n){
search(ln+1,rn,n,len+1,cur+"(");
}
// The number of right parentheses is less than that of left parentheses
if(rn < ln){
search(ln,rn+1,n,len+1,cur+")");
}
}
}
边栏推荐
- 3分钟带你了解微信小程序开发
- The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
- Overview of super-resolution reconstruction of remote sensing images
- Développement d'un module d'élimination des bavardages à clé basé sur la FPGA
- C language -- structs, unions, enumerations, and custom types
- 简易博客系统
- 登录mysql输入密码时报错,ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO/YES
- Detailed explanation of serialization and deserialization
- Recommended papers on remote sensing image super-resolution
- Security xxE vulnerability recurrence (XXe Lab)
猜你喜欢

BUAA计算器(表达式计算-表达式树实现)

KS003基于JSP和Servlet实现的商城系统

【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用

Data analysis Seaborn visualization (for personal use)

How do we make money in agriculture, rural areas and farmers? 100% for reference

【可调延时网络】基于FPGA的可调延时网络系统verilog开发

3.1 detailed explanation of rtthread serial port device (V1)
![Cf464e the classic problem [shortest path, chairman tree]](/img/6b/65b2dc62422a45cc72f287c38dbc58.jpg)
Cf464e the classic problem [shortest path, chairman tree]
![[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)](/img/8a/068faf3e8de642c9e3c4118e6084aa.jpg)
[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)

2.13 weekly report
随机推荐
Mathematical modeling regression analysis relationship between variables
多项目编程极简用例
Pytoch foundation - (2) mathematical operation of tensor
[Qt5] QT QWidget immediately appears and disappears
2.2 STM32 GPIO operation
The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
2.13 weekly report
Ethernet port &arm & MOS &push-pull open drain &up and down &high and low sides &time domain and frequency domain Fourier
有条件地 [JsonIgnore]
/usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
C#(三十)之C#comboBox ListView treeView
Redis (replicate dictionary server) cache
Cubemx transplantation punctual atom LCD display routine
C (thirty) C combobox listview TreeView
在字节做测试5年,7月无情被辞,想给划水的兄弟提个醒
Error 1045 (28000): access denied for user 'root' @ 'localhost' (using password: no/yes
Record the pit of NETCORE's memory surge
【按鍵消抖】基於FPGA的按鍵消抖模塊開發
C#(二十八)之C#鼠标事件、键盘事件