def dfs(target_word, current_word):
vowels = ['A', 'E', 'I', 'O', 'U']
temp_word = current_word
if current_word == target_word:
return count
if len(current_word) >= 5:
return -1
for vowel in vowels:
current_word += vowel
count += 1
result = dfs(target_word, current_word)
if result != -1:
return result
current_word = temp_word
return -1
def solution(word):
global count
current_word = ""
count = 0
answer = dfs(word, current_word)
return answer
word = "AAAE"
>> 10
vowels 리스트에는 모음 'A', 'E', 'I', 'O', 'U'를 저장한다.
temp_word 변수에는 현재 단어 current_word를 저장한다.
current_word와 target_word가 동일한 경우, 이 단어가 사전에서 몇 번째 단어인지 저장된 count를 반환한다.
current_word의 길이가 5 이상인 경우 더 이상 모음을 추가할 수 없으므로 -1을 반환한다.
vowels 리스트의 각 모음에 대해 다음 작업을 수행한다.
모든 반복이 완료되고도 목표 단어를 찾지 못한 경우, -1을 반환한다.
