[99클럽 코테 스터디 16일차 TIL] 프로그래머스 - 모음사전
99클럽 코테 스터디 16일차 TIL 입니다.
Previous[99클럽 코테 스터디 15일차 TIL] LeetCode - Prefix and Suffix SearchNext[99클럽 코테 스터디 17일차 TIL] 백준 - 촌수계산
Last updated
99클럽 코테 스터디 16일차 TIL 입니다.
Last updated
import java.util.Map;
import java.util.HashMap;
class Solution {
public int solution(String word) {
Map<String, Integer> map = new HashMap<>();
String[] arr = {"A", "E", "I", "O", "U"};
int index = 1;
for (int i = 0; i < 5; i++) {
map.put(arr[i], index++);
for (int j = 0; j < 5; j++) {
map.put(arr[i] + arr[j], index++);
for (int k = 0; k < 5; k++) {
map.put(arr[i] + arr[j] + arr[k], index++);
for (int o = 0; o < 5; o++) {
map.put(arr[i] + arr[j] + arr[k] + arr[o], index++);
for (int p = 0; p < 5; p++) {
map.put(arr[i] + arr[j] + arr[k] + arr[o] + arr[p], index++);
}
}
}
}
}
return map.get(word);
}
}import java.util.Map;
import java.util.HashMap;
class Solution {
private Map<String, Integer> map = new HashMap<>();
private int index = 0;
public int solution(String word) {
String[] vowels = {"A", "E", "I", "O", "U"};
for (int i = 0; i < 5; i++) {
insert(vowels, "", i);
}
return map.get(word);
}
// vowel, depth : "", 0 -> "A", 0 -> ...
public void insert(String[] vowels, String vowel, int depth) {
if (vowel.length() == 5) return;
String word = vowel + vowels[depth]; // "" + "A" -> "A" + "A" -> ...
index++; // 1 -> 2
map.put(word, index); // "A", 1 -> "AA", 2 -> ...
for (int i = 0; i < 5; i++) {
insert(vowels, word, i); // word, i : "A", 0 -> ...
}
}
}import java.util.Map;
import java.util.HashMap;
class Solution {
private Map<String, Integer> map = new HashMap<>();
private int index = 0;
public int solution(String word) {
String[] vowels = {"A", "E", "I", "O", "U"};
insert(vowels, "");
return map.get(word);
}
public void insert(String[] vowels, String vowel) {
map.put(vowel, index++);
if (vowel.length() == 5) return;
for (int i = 0; i < 5; i++) {
insert(vowels, vowel + vowels[i]);
}
}
}import java.util.Map;
import java.util.HashMap;
class Solution {
private Map<String, Integer> map = new HashMap<>();
private int index = 0;
private boolean isWord = false;
public int solution(String word) {
String[] vowels = {"A", "E", "I", "O", "U"};
insert(vowels, "", word);
return map.get(word);
}
public void insert(String[] vowels, String vowel, String word) {
map.put(vowel, index++);
if (vowel.equals(word)) {
isWord = true;
return;
}
if (vowel.length() == 5 || isWord) return;
for (int i = 0; i < 5; i++) {
insert(vowels, vowel + vowels[i], word);
}
}
}