https://school.programmers.co.kr/learn/courses/30/lessons/84512
DFS를 활용한 풀이이다.
function solution(word) {
function getResult(str) {
if (str === word) return true;
if (str.length === 5) return false;
for (let i = 0; i < words.length; i++) {
answer++;
if (getResult(str + words[i])) return true;
}
return false;
}
let answer = 0;
let words = ["A", "E", "I", "O", "U"];
getResult("");
return answer;
}
수식을 활용한 풀이이다.
https://nukw0n-dev.tistory.com/18
function sumSquare(idx) {
let sum = 0;
for(let i = idx; i>=0; i-=1) {
sum += 5**i;
}
return sum;
}
function solution(word) {
let answer = 0;
const aeiou = { 'A': 0, 'E': 1, 'I': 2, 'O': 3, 'U': 4 };
[...word].forEach((w, idx) => {
const val = aeiou[w];
answer += val * sumSquare(4-idx) + 1;
})
return answer;
}