- 난이도: Lv2
프로그래머스 링크: https://school.programmers.co.kr/learn/courses/30/lessons/84512
풀이 링크(GitHub): hayannn/CodingTest_Java/프로그래머스/2/모음사전
풀이 시간 : 25분
import java.util.*;
class Solution {
static String[] words = {"A", "E", "I", "O", "U"};
static int count, answer;
public int solution(String word) {
count = 0;
answer = 0;
dfs("", word, 0);
return answer;
}
static void dfs(String str, String target, int len) {
if (str.equals(target)) {
answer = count;
return;
}
if (len == 5) return;
for (int i = 0; i < 5; i++) {
count++;
dfs(str + words[i], target, len + 1);
if (answer > 0) return;
}
}
}