나의 개발일지

[프로그래머스] Lv.2 모음사전 [Python, 파이썬] 본문

프로그래머스

[프로그래머스] Lv.2 모음사전 [Python, 파이썬]

YoonJuHan 2023. 12. 15. 15:24

 

def dfs(w, word, words):
    global answer, flag
    
    if word == w:
        flag = True
        return
    
    if len(w) != 5:
        for i in range(len(words)):
            if flag:
                return
            answer += 1
            dfs(w+words[i], word, words)
            
answer = 0
flag = False

def solution(word):

    words = ['A', 'E', 'I', 'O', 'U']
                
    dfs("", word, words)
    
    return answer
Comments