[java] 프로그래머스 - 모음사전

0

[문제링크 - 프로그래머스 - 모음사전] https://school.programmers.co.kr/learn/courses/30/lessons/84512

import java.util.*;

class Solution {
    static List<String> list = new ArrayList<>();
    public int solution(String word) {
        int answer = 0;
        String[] words = {"A", "E", "I", "O", "U"};
        dfs("", words);
        answer = list.indexOf(word);
        return answer;
    }

    public void dfs(String temp, String[] words){
        list.add(temp);
        if(temp.length() == 5) return;
        for(int i=0; i<5; i++){
            dfs(temp+words[i], words);
        }
    }
}
profile
초심 잃지 않기

0개의 댓글

관련 채용 정보