当前位置:网站首页>【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+")");
}
}
}
边栏推荐
- 在字节做测试5年,7月无情被辞,想给划水的兄弟提个醒
- The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
- Blue Bridge Cup - day of week
- math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)
- 【FPGA教程案例11】基于vivado核的除法器设计与实现
- [001] [stm32] how to download STM32 original factory data
- mysql从一个连续时间段的表中读取缺少数据
- Schnuka: visual positioning system working principle of visual positioning system
- MySQL 中的数据类型介绍
- 2.2 STM32 GPIO operation
猜你喜欢
mysql从一个连续时间段的表中读取缺少数据
An article will give you a comprehensive understanding of the internal and external components of "computer"
ESP32(基于Arduino)连接EMQX的Mqtt服务器上传信息与命令控制
BUAA计算器(表达式计算-表达式树实现)
Ethernet port &arm & MOS &push-pull open drain &up and down &high and low sides &time domain and frequency domain Fourier
The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
Flask learning and project practice 8: introduction and use of cookies and sessions
Scalpel like analysis of JVM -- this article takes you to peek into the secrets of JVM
C (thirty) C combobox listview TreeView
[practice] mathematics in lottery
随机推荐
Multi project programming minimalist use case
Esp32 (based on Arduino) connects the mqtt server of emqx to upload information and command control
Containerization Foundation
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
多项目编程极简用例
cookie,session,Token 这些你都知道吗?
math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)
The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
20、 EEPROM memory (AT24C02) (similar to AD)
Blue Bridge Cup - Castle formula
Prime protocol announces cross chain interconnection applications on moonbeam
Plus d'un milliard d'utilisateurs de grandes entreprises comme Facebook ont été compromis, il est temps de se concentrer sur le did
Chinese brand hybrid technology: there is no best technical route, only better products
2.1 rtthread pin device details
潘多拉 IOT 开发板学习(HAL 库)—— 实验9 PWM输出实验(学习笔记)
Why do you want to start pointer compression?
RT thread -- FTP of LwIP (2)
C form application of C (27)
Scalpel like analysis of JVM -- this article takes you to peek into the secrets of JVM
Pytoch foundation - (2) mathematical operation of tensor