https://school.programmers.co.kr/learn/courses/30/lessons/84512

import java.util.*;
class Solution {
public static String[] alpha = {"A","E","I","O","U"};
public static ArrayList<String> list = new ArrayList<>();
public static void dfs(String word, String makeWord, int depth)
{
if(5 == depth)
{
list.add(makeWord);
return;
}
for(int i=0; i<5; i++)
{
if(!list.contains(makeWord))
{
list.add(makeWord);
}
dfs(word, makeWord+alpha[i], depth+1);
}
}
public static int solution(String word) {
int cnt = 0;
dfs(word,"", 0);
list.remove(0);
for(var str : list) {
cnt++;
if (word.equals(str))
{
break;
}
}
return cnt;
}
}
익힐것 :
1. 보통의 dfs랑 다르게 chk이 없음
2. if(depth == 5)면 바로 add, 중간에 for문에선 contains체크 했음.