๋ฌธ์ ๐ฝ
https://school.programmers.co.kr/learn/courses/30/lessons/84512
๋ค๋ฅธ์ฌ๋ ํ์ด ๐ฝ
const VOWELS = ['A','E','I','O','U','']
const f=(a)=>VOWELS.map(b=>b+a)
function solution(word) {
return Array.from(
new Set(VOWELS
.map(f).flat()
.map(f).flat()
.map(f).flat()
.map(f).flat())
).sort().indexOf(word)
}
๋ดํ์ด๐ฝ
1. ์ฑ๊ณต โญ
function solution(word) {
let charArr = ["A","E","I","O","U"]
let t = []
var answer = 0;
const dfs=(cha)=>{
if(cha.length>5){ return }
t.push(cha);
for(let i=0; i<5; i++){
dfs(cha+charArr[i])
}
}
for(let a of charArr){
dfs(a)
}
t.sort((a,b)=> b-a)
answer=1+t.indexOf(word)
return answer;
}
๋๋์ ๐ฝ
์ํ๋ฒณ์ผ๋ก ๋ง๋ค ์ ์๋ ๋ชจ๋ ๊ฒฝ์ฐ์ ์๋ 3,125 ๊ฐ ์ด๋ฏ๋ก dfs๋ฅผ ์ด์ฉํด๋ ์๊ฐ์ ์ถฉ๋ถํ๋ค๋ ๊ฑธ ์ธ์งํ ์๊ฐ ํ์ด๊ฐ ์ฌ์ด ์ก๋ค.