일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- java collection
- Access-Control-Allow-Origin
- CORS policy: No 'Access-Control-Allow-Origin'
- Set
- Hystrix Read time out
- mariadb 다국어
- cors
- message protocol
- #actuator
- mysql 한국어
- mqtt
- IOT
- xrdp
- TreeMap
- db utf8
- #spring boot admin
- backtracking
- mosquitto
- com.netflix.zuul.exception.ZuulException
- #spring boot
- com.netflix.zuul.exception.ZuulException: Hystrix Readed time out
- HashMap
- emqx
- #MSA
- 크로스도메인
- mstsc
- mariadb 한국어
- mysql 다국어
- ArrayList
- 원격
- Today
- Total
miin29na
[알고리즘]22. Generate Parentheses[] 본문
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
For example, given n = 3, a solution set is:
[ "((()))", "(()())", "(())()", "()(())", "()()()" ]
class Solution { public List<String> generateParenthesis(int n) { List<String> result = new ArrayList<>(); backtrack(result, "", 0 , 0, n); return result; }
public void backtrack(List<String> result, String cur, int open, int close, int max) { System.out.println(cur + ", oepn : " + open + ", close : " + close); if (cur.length() == max * 2) { result.add(cur); return; }
if (open < max) { backtrack(result, cur+"(" , open+1, close, max); }
if (close < open) { backtrack(result, cur+")", open, close+1, max); } } } |
, oepn : 0, close : 0
(, oepn : 1, close : 0
((, oepn : 2, close : 0
(((, oepn : 3, close : 0
(((), oepn : 3, close : 1
((()), oepn : 3, close : 2
((())), oepn : 3, close : 3
((), oepn : 2, close : 1
(()(, oepn : 3, close : 1
(()(), oepn : 3, close : 2
(()()), oepn : 3, close : 3
(()), oepn : 2, close : 2
(())(, oepn : 3, close : 2
(())(), oepn : 3, close : 3
(), oepn : 1, close : 1
()(, oepn : 2, close : 1
()((, oepn : 3, close : 1
()((), oepn : 3, close : 2
()(()), oepn : 3, close : 3
()(), oepn : 2, close : 2
()()(, oepn : 3, close : 2
()()(), oepn : 3, close : 3