[프로그래머스][JAVA] 모음 사전 (순열, 수학)

[프로그래머스][JAVA] 모음 사전 (순열, 수학)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

import java.util. * ; class Solution { Set < String > wordSet = new HashSet < > (); StringBuilder sb = new StringBuilder(); String [] alp = new String []{ "" , "A" , "E" , "I" , "O" , "U" }; private void permutation( int pos){ if (pos = = 5 ){ wordSet. add (sb. toString ()); return ; } for ( int i = 0 ; i < alp. length ; i + + ){ sb.append(alp[i]); permutation(pos + 1 ); if (i ! = 0 ) sb.deleteCharAt(sb. length () - 1 ); } } public int solution( String word) { permutation( 0 ); List < String > wordList = new ArrayList < > (wordSet); Collections.sort(wordList); // for(int i=0; i<10; i++){ // System.out.println(wordList.get(i)); // } int answer = wordList. indexOf (word); return answer; } } Colored by Color Scripter

from http://aig2029.tistory.com/353 by ccl(A) rewrite - 2021-10-28 21:27:58