Notice
Recent Posts
Recent Comments
Link
나의 개발일지
[프로그래머스] Lv.2 모음사전 [Python, 파이썬] 본문
- 문제 : https://school.programmers.co.kr/learn/courses/30/lessons/84512
- 🔑 DFS로 완전 탐색
- A ~ UUUUU까지 만들 수 있는 dfs 함수를 생성
- 원하는 단어를 찾을 때까지 answer 올리고
- 찾았으면 계속 리턴만해서 빠져나오기
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
'프로그래머스' 카테고리의 다른 글
[프로그래머스] Lv.2 방문 길이 [Python, 파이썬] (0) | 2023.12.15 |
---|---|
[프로그래머스] Lv.3 최고의 집합 [Python, 파이썬] (1) | 2023.12.15 |
[프로그래머스] Lv.3 야근 지수 [Python, 파이썬] (0) | 2023.12.14 |
[프로그래머스] Lv. 2 할인 행사 [Python, 파이썬] (0) | 2023.12.14 |
[프로그래머스] Lv.2 행렬 테두리 회전하기 [Python, 파이썬] (0) | 2023.11.27 |
Comments