- 난이도: Lv4
프로그래머스 링크: https://school.programmers.co.kr/learn/courses/30/lessons/12929
풀이 링크(GitHub): hayannn/CodingTest_Java/프로그래머스/4/올바른 괄호의 갯수
풀이 시간 : 35분
class Solution {
static int answer = 0;
public int solution(int n) {
dfs(n, 0, 0);
return answer;
}
static public void dfs(int max, int open, int close) {
if (open == max && close == max) {
answer++;
return;
}
if (open < max) {
dfs(max, open + 1, close);
}
if (close < open) {
dfs(max, open, close + 1);
}
}
}