ABOUT ME

Today
Yesterday
Total
  • [프로그래머스/javascript] 모음사전 (다시 풀기)
    카테고리 없음 2023. 3. 7. 14:14
    function solution(word) {
        var answer = 0;
        const alphabet = ["A","E","I","O","U"]
        const dictionary = [];
        const char = "";
        function dfs(wordA){
            if(wordA.length<=5){
            if(wordA!==""){
            dictionary.push(wordA)}
            for(let i=0;i<alphabet.length;i++){
                dfs(wordA+alphabet[i])
            }
            }
        }
    
        dfs("")
    
        return dictionary.indexOf(word)+1
    }

    dictionary에 삽입하면서 word가 나오면 중단하고 싶었는데, 어떻게 중단해야할지 몰라서... indexOf로 풀었다. 다행히 런타임에러가 나오진 않았다.

     

Designed by Tistory.