본문 바로가기
알고리즘 & 자료구조/프로그래머스

올바른 괄호의 개수

by 신재권 2022. 12. 3.
package programmers;

public class 올바른괄호의개수 {

   private static int[] d;

   //D[i]= D[0] * D[i-1] + D[1] * D[i-2] + ... + D[i-1]*D[0];

   public static int solution(int n) {
      return init(n);
   }

   private static int init(int n) {
      d = new int[n + 1];
      d[0] = d[1] = 1;
      for (int i = 2; i <= n; i++) {
         for (int j = 1; j <= i; j++) {
            d[i] += d[j - 1] * d[i - j];
         }
      }
      return d[n];
   }

   public static void main(String[] args) {
      System.out.println(solution(2));
      System.out.println(solution(3));
   }
}

'알고리즘 & 자료구조 > 프로그래머스' 카테고리의 다른 글

가장 가까운 같은 글자  (0) 2022.12.13
정수 삼각형  (0) 2022.12.04
게임 맵 최단거리  (0) 2022.12.02
위장  (0) 2022.12.02
숫자게임  (0) 2022.11.19