当前位置:网站首页>【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+")");
}
}
}
边栏推荐
- Exchange bottles (graph theory + thinking)
- 登录mysql输入密码时报错,ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO/YES
- 2.1 rtthread pin device details
- User perceived monitoring experience
- Data analysis Seaborn visualization (for personal use)
- Why do you want to start pointer compression?
- Custom event of C (31)
- [meisai] meisai thesis reference template
- 自动化测试怎么规范部署?
- Oracle ORA error message
猜你喜欢
![[adjustable delay network] development of FPGA based adjustable delay network system Verilog](/img/82/7ff7f99f5164f91fab7713978cf720.png)
[adjustable delay network] development of FPGA based adjustable delay network system Verilog

Benefits of automated testing
![[PSO] Based on PSO particle swarm optimization, matlab simulation of the calculation of the lowest transportation cost of goods at material points, including transportation costs, agent conversion cos](/img/41/27ce3741ef29e87c0f3b954fdef87a.png)
[PSO] Based on PSO particle swarm optimization, matlab simulation of the calculation of the lowest transportation cost of goods at material points, including transportation costs, agent conversion cos

自动化测试的好处

Thread sleep, thread sleep application scenarios

多项目编程极简用例

2.2 STM32 GPIO operation

JVM的手术刀式剖析——一文带你窥探JVM的秘密

Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage

C#(二十八)之C#鼠标事件、键盘事件
随机推荐
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
[Key shake elimination] development of key shake elimination module based on FPGA
C#(二十八)之C#鼠标事件、键盘事件
In Net 6 CS more concise method
Multi project programming minimalist use case
在 .NET 6 中使用 Startup.cs 更简洁的方法
Detailed explanation of serialization and deserialization
JS Vanke banner rotation chart JS special effect
User perceived monitoring experience
自动化测试的好处
【Qt5】Qt QWidget立刻出现并消失
【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用
Ks008 SSM based press release system
Containerization Foundation
No qualifying bean of type ‘......‘ available
[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
[practical exercise] face location model based on skin color
/usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
Ybtoj coloring plan [tree chain dissection, segment tree, tarjan]
[meisai] meisai thesis reference template