Skip to content

Commit 36d4a9f

Browse files
authored
Merge pull request #1375 from AlgorithmWithGod/zinnnn37
[20251111] PGM / LV2 / 모음사전 / 김민진
2 parents f2fb85f + d2e3dbf commit 36d4a9f

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
```java
2+
import java.util.ArrayList;
3+
import java.util.List;
4+
5+
public class PGM_LV2_모음사전 {
6+
7+
private static final String[] vowels = {"A", "E", "I", "O", "U"};
8+
9+
private static int ans;
10+
private static String word;
11+
private static List<String> words;
12+
13+
private static void dfs(int depth, String tmp) {
14+
if (depth > 5) {
15+
return;
16+
}
17+
18+
words.add(tmp);
19+
20+
for (int i = 0; i < 5; i++) {
21+
dfs(depth + 1, tmp + vowels[i]);
22+
}
23+
}
24+
25+
public int solution(String w) {
26+
word = w;
27+
words = new ArrayList<>();
28+
29+
dfs(0, "");
30+
31+
int len = words.size();
32+
for (int i = 0; i < len; i++) {
33+
if (words.get(i).equals(word)) {
34+
ans = i;
35+
break;
36+
}
37+
}
38+
39+
return ans;
40+
}
41+
}
42+
```

0 commit comments

Comments
 (0)