import java.util.HashSet;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
class Solution {
static HashSet<String> dictionary;
public int solution(String word) {
int answer = 0;
String[] words = {"A","E","I","O","U"};
dictionary = new HashSet<>();
makeDictionary("",words);
List<String> dict = new ArrayList<>(dictionary);
Collections.sort(dict);
for(int i=0; i<dict.size(); i++){
if(dict.get(i).equals(word)){
answer=i;
break;
}
}
return answer;
}
static void makeDictionary(String s,String[] words){
if(s.length()>5) return;
dictionary.add(s);
for(int i=0; i<5; i++){
makeDictionary(s+words[i],words);
}
}
}
중복이 없는 HashSet을 이용한 후 ArrayList를 통해 정렬
'NOTE > 프로그래머스' 카테고리의 다른 글
소수 찾기 (0) | 2022.10.15 |
---|---|
피로도 (0) | 2022.10.15 |
조건별로 분류하여 주문상태 출력하기 - Oracle (0) | 2022.10.12 |
5월 식품들의 총매출 조회하기 (0) | 2022.10.12 |
식품분류별 가장 비싼 식품의 정보 조회하기 - Oracle (0) | 2022.10.12 |