프로그래머스 완전탐색 모음사전 [JAVA] - 22년 9월 15일

Denia·2022년 9월 15일
0

코딩테스트 준비

목록 보기
69/201
package com.company;

import java.util.ArrayList;
import java.util.List;

class Solution {
    List<String> dictionary;
    String[] alphabetArr = {"A", "E", "I", "O", "U"};
    public int solution(String word) {
        int answer;
        dictionary = new ArrayList<>();

        dfs("");

        answer = dictionary.indexOf(word);

        return answer;
    }

    private void dfs(String str) {
        dictionary.add(str);

        if(str.length() >= alphabetArr.length) {
            return;
        }

        for (String alphabet : alphabetArr) {
            dfs(str + alphabet);
        }
    }
}

profile
HW -> FW -> Web

0개의 댓글