博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Generate Parentheses
阅读量:4542 次
发布时间:2019-06-08

本文共 665 字,大约阅读时间需要 2 分钟。

dfs 的一个关键是termination condition

public class Solution {    public ArrayList
generateParenthesis(int n) { ArrayList
res = new ArrayList
(); if(n<1) return res; dfs(n,n,res,new String()); return res; } private void dfs(int nl, int nr,ArrayList
res, String item){ if(nr
nl not working!!! if(nr==0 && nl==0) res.add(item); if(nl>0) dfs(nl-1, nr, res, item+'('); if(nr>0) dfs(nl, nr-1, res, item+')'); }}

 

转载于:https://www.cnblogs.com/jiajiaxingxing/p/4545306.html

你可能感兴趣的文章
枚举也能直接转换为对应的数值输出
查看>>
angularjs1-7,供应商
查看>>
让插件帮你优化代码
查看>>
Java之路——Java初接触
查看>>
2018.12.27学习JavaScript
查看>>
理工之 A+B Problem III
查看>>
软件工程第一次作业
查看>>
【Android 界面效果24】Intent和PendingIntent的区别
查看>>
node学习之搭建服务器并加装静态资源
查看>>
android 按menu键解锁功能的开关
查看>>
Linux 下的dd命令使用详解
查看>>
POJ-1273 Drainage Ditches 最大流Dinic
查看>>
ASP.NET学习记录点滴
查看>>
[Noip2016] 愤怒的小鸟
查看>>
JAVA wait()和notifyAll()实现线程间通讯
查看>>
python全栈脱产第11天------装饰器
查看>>
[总结]数据结构(板子)
查看>>
C# 笔记
查看>>
[转]人人店短信插件开发
查看>>
[转]c# System.IO.Ports SerialPort Class
查看>>