슈콩

[프로그래머스] Lv.2 모음사전 본문

Algorithms/Programmers

[프로그래머스] Lv.2 모음사전

shukong 2025. 10. 16. 01:44

 

 

[문제]

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

 

프로그래머스

SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

 

[소스 코드]

import java.util.*;
class Solution {
    List<String> list;
    String[] w = {"A","E","I","O","U"};
    public int solution(String word) {
        int answer = 0;
        list = new ArrayList<>();
        for(int i=1;i<=5;i++){
            make(0,i,"");
        }
        Collections.sort(list);
        return list.indexOf(word)+1;
    }
    private void make(int cnt,int max,String s){
        if(cnt==max){
            list.add(s);
            return;
        }
        for(int i=0;i<5;i++){
            make(cnt+1,max,s+w[i]);
        }
    }
}