모음사전

yonii·2021년 10월 8일
0

🔗문제 링크

구현코드

import java.util.*;
class Solution {
    static String p = "";
    static char[] w = {'A','E','I','O','U'};
    static ArrayList<String> list = new ArrayList<>();
    
    public int solution(String word) {
        permutation(0);
        Collections.sort(list);
        
        int answer = list.indexOf(word)+1;
        return answer;
    }
    
    static void permutation(int L){
        if(L==w.length){
            return;
        }
        for(int i=0;i<w.length;i++){
            p += w[i];
            list.add(p);
            permutation(L+1);
            p = p.substring(0,L);
        }

    }
}
  • 알고리즘

    list: 중복순열(dfs)의 모든 경우의 수를 저장하기 위한 리스트
    중복 순열 돌면서 모든 경우의 수 list에 add
    list 정렬

profile
공부하려고 노력ing....

0개의 댓글