Algorithms in Python/Programmers - ALGO ⭐️

모음사전 - 완전탐색

cat_no2 2024. 6. 5. 10:46

def solution(word):
    alphabets = ['A', 'E', 'I', 'O', 'U']
    global answer 
    answer = 0 

    def dfs(string):
        global answer 
        answer += 1 
        #guard closure 
        if string == word:
            return True
        #guard closure 
        if len(string) == 5:
            return False
        #find the given word 
        for alpha in alphabets:
            if dfs(string + alpha) == True:
                return True 

    for alpha in alphabets:
        if dfs(alpha) == True:
            return answer

'Algorithms in Python > Programmers - ALGO ⭐️' 카테고리의 다른 글

최솟값 만들기  (0) 2024.07.02
카펫 - 완전탐색  (0) 2024.06.05
최소 직사각형  (0) 2024.06.03
네트워크  (0) 2024.05.18
구명보트  (0) 2024.05.16