Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- LEVEL 2
- Lv. 1
- Python
- 자바스크립트
- Lv. 3
- 티스토리챌린지
- select
- 소프티어
- 동적계획법
- programmers
- Lv. 2
- Baekjoon
- DP
- Lv. 0
- SQL 고득점 KIT
- Dynamic Programming
- javascript
- 파이썬
- 오블완
- bfs
- dfs
- 프로그래머스
- SQL
- Java
- level 3
- group by
- 깊이 우선 탐색
- join
- softeer
- 너비 우선 탐색
Archives
- Today
- Total
몸과 마음이 건전한 SW 개발자
프로그래머스 [Lv. 2] 모음 사전 {언어 : Python} 본문
문제 링크
https://school.programmers.co.kr/learn/courses/30/lessons/84512
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
정답 코드
cnt = 0
answer = 0
def solution(word):
def dictSearch(length, string):
global cnt, answer
if length:
if word == string:
answer = cnt
if length == 5:
return
for alpha in ["A", "E", "I", "O", "U"]:
cnt += 1
dictSearch(length+1, string+alpha)
dictSearch(0, "")
return answer
풀이 방법
- length가 존재하면 단어가 만들어진 것이므로 word와 비교한다.
- length가 5이하이므로 5에서 재귀를 종료한다.
- "A" 부터 문자를 만들어주는데
- "A" 다음은 "AA"가 만들어진다.
- 마지막으로 word와 일치하면 현재 cnt를 answer에 넣어주고 출력한다.
느낀점
- 재귀이면서 조합이었던 문제가 아닐까 싶다.
'알고리즘' 카테고리의 다른 글
프로그래머스 [Lv. 1] 신규 아이디 추천 {언어 : JavaScript} (0) | 2024.02.22 |
---|---|
프로그래머스 [Lv. 2] 하노이의 탑 {언어 : JavaScript} (0) | 2024.02.21 |
Softeer Level 2 X marks the Spot {언어 : JavaScript} (0) | 2024.02.13 |
Softeer Level 2 X marks the Spot {언어 : Python} (0) | 2024.02.13 |
Softeer Level 3 통근버스 출발 순서 검증하기 Python (0) | 2024.02.08 |