当前位置:网站首页>【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+")");
}
}
}
边栏推荐
- 自动化测试怎么规范部署?
- Align items and align content in flex layout
- Mathematical modeling regression analysis relationship between variables
- /usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
- [analysis of variance] single factor analysis and multi factor analysis
- 【按鍵消抖】基於FPGA的按鍵消抖模塊開發
- How to modify field constraints (type, default, null, etc.) in a table
- Record the pit of NETCORE's memory surge
- Flask learning and project practice 9: WTF form verification
- 潘多拉 IOT 开发板学习(HAL 库)—— 实验9 PWM输出实验(学习笔记)
猜你喜欢

Pytoch foundation - (1) initialization of tensors

User experience index system

C#(三十一)之自定义事件

Exchange bottles (graph theory + thinking)
![P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]](/img/b1/dbfc42d66548476300501dd839abef.jpg)
P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]

Plus d'un milliard d'utilisateurs de grandes entreprises comme Facebook ont été compromis, il est temps de se concentrer sur le did

KS008基于SSM的新闻发布系统

Interface idempotency

cookie,session,Token 这些你都知道吗?

Thread sleep, thread sleep application scenarios
随机推荐
Database, relational database and NoSQL non relational database
Record the pit of NETCORE's memory surge
Proof of Stirling formula
Remote Sensing Image Super-resolution and Object Detection: Benchmark and State of the Art
3.2 detailed explanation of rtthread serial port device (V2)
[optimization model] Monte Carlo method of optimization calculation
20、 EEPROM memory (AT24C02) (similar to AD)
mysql关于自增长增长问题
3分钟带你了解微信小程序开发
简易博客系统
C language circular statement
Mapping between QoE and KQI
BUAA calculator (expression calculation - expression tree implementation)
In Net 6 CS more concise method
Data analysis Seaborn visualization (for personal use)
MySQL reads missing data from a table in a continuous period of time
Blue Bridge Cup - Castle formula
Codeforces Global Round 19
Custom event of C (31)
Ybtoj coloring plan [tree chain dissection, segment tree, tarjan]