当前位置:网站首页>Bracket generation ---2022/02/25
Bracket generation ---2022/02/25
2022-06-11 17:34:00 【City Pig】
List of articles
Title Description
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 .
Title source
Their thinking
First of all, I want to add some knowledge about depth first search and breadth first search .
Depth first search is equivalent to the prior traversal of the tree ( Starting from the root node , The order traverses the left subtree , Then traverse the right subtree first ), Usually, the data storage concept of stack is used for calculation ; Breadth first search is equivalent to traversing the tree hierarchy , Usually, the data storage concept of queue is used for calculation .
Code implementation
class Solution {
List<String> res=new ArrayList<>();
public List<String> generateParenthesis(int n) {
dfs(n,n,"");
return res;
}
public void dfs(int left,int right,String curStr){
if(left==0&&right==0)
{
res.add(curStr);
return;
}
if(left>0){
dfs(left-1,right,curStr+"(");
}
if(right>left){
dfs(left,right-1,curStr+")");
}
}
}
Performance evaluation

The optimization direction has not been considered for the time being .
边栏推荐
- Chorus翻译
- 【线上问题】Timeout waiting for connection from pool 问题排查
- [MySQL] detailed explanation of redo log, undo log and binlog (4)
- Dynamic: capturing network dynamics using dynamic graph representation learning
- 自动化测试-Selenium
- Mathematical basis of information security Chapter 4 -- quadratic residual and square root
- 信息安全数学基础 Chapter 3——有限域(一)
- 端口规划与APJ
- Connect the server with springboard / fortress through xshell
- Mathematical foundations of information security Chapter 3 - finite fields (I)
猜你喜欢

Xie Yang, CEO of authing, was selected into Forbes' 30 under 30 Asia list in 2021

Service learning notes 02- actual combat startservice and bindservice

Authing 双周动态:Authing 论坛上线(4.25-5.8)

Activity | authing's first channel cooperation activity came to a successful conclusion

测试基础之:黑盒测试

Custom or subscription? What is the future development trend of China's SaaS industry?

Format eslint automatique lorsque vscode enregistre le Code

What problems are exposed when all Sohu employees are cheated?

05_特征工程—降维

Dynamic: capturing network dynamics using dynamic graph representation learning
随机推荐
What is the minimum change price of PTA futures? How can PTA futures be safe?
6-1 从文件读取字符串(*)
有效的括号---2022/02/23
05_ Feature Engineering - dimension reduction
使用exe4j 将.jar文件打包为.exe文件
04_ Feature engineering feature selection
【Mysql】redo log,undo log 和binlog详解(四)
Don't you understand the design and principle of thread pool? Break it up and crush it. I'll teach you how to design the thread pool
Port planning and APJ
Service学习笔记01-启动方式与生命周期
tidb-gc相关问题
信息安全数学基础 Chapter 4——二次剩余与方根
Set object mapping + scene 6-face mapping + create space in threejs
6-8 有结构文件的读写1
Chorus翻译
字符串转数值
Bentley 使用 Authing 快速实现应用系统与身份的集成
Activity | authing's first channel cooperation activity came to a successful conclusion
拜登下令强制推行零信任架构
【线上问题】Timeout waiting for connection from pool 问题排查