This repository was archived by the owner on Mar 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
[2023-10-02] wooyeol #297 #315
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
""" | ||
스킬트리 | ||
https://school.programmers.co.kr/learn/courses/30/lessons/49993 | ||
|
||
풀이시간 | ||
10:23 ~ 10:39 (16분) | ||
|
||
문제 조건 | ||
1 <= len(skill) <= 26 | ||
1 <= len(skill_trees) <= 20 | ||
2 <= 각 skill_trees의 길이 <= 26 | ||
|
||
시간 복잡도 : | ||
O(20 * 26) | ||
|
||
접근법 | ||
무슨 알고리즘으로 풀이 할 수 있을까? -> 완전 탐색 | ||
|
||
데이터의 중복과 갯수가 크게 문제 되지 않기 때문에 완전 탐색으로 단순 구현을 진행하였습니다. | ||
|
||
완전 탐색 과정 | ||
각각의 스킬트리 과정을 확인합니다. | ||
- 선행 스킬의 인덱스를 증가시키며 선행 스킬이 순서대로 주어지는지 확인하기 | ||
- 스킬트리의 스킬을 하나씩 확인하고 선행 스킬에 포함된다면 등장해야하는 선행 스킬과 비교 | ||
- 정상일 경우 다음 선행 스킬의 인덱스로 증가 | ||
- 아니라면 인터럽트 | ||
- 인터럽트가 일어나지 않은 스킬트리는 정답으로 인정 | ||
""" | ||
|
||
def solution(skill, skill_trees): | ||
answer = 0 | ||
|
||
# 선행 스킬의 Set화 | ||
set_skill = set(skill) | ||
|
||
# 선행 스킬의 List화 | ||
skill = list(skill) | ||
|
||
# 주어진 모든 스킬트리 검사 | ||
for skill_tree in skill_trees: | ||
# 현재 검사해야하는 선행 스킬의 인덱스 | ||
skill_idx = 0 | ||
|
||
# 정상적으로 검사가 종료되었는지 Interrupt 여부 확인 | ||
interrupt = False | ||
|
||
# 현재 스킬트리의 스킬을 하나씩 검사 | ||
for alpha in skill_tree: | ||
# 현재 스킬트리의 스킬이 선행 스킬 내부에 존재하고 | ||
if alpha in set_skill: | ||
# 현재 검사해야하는 선행 스킬의 인덱스를 가지는 스킬과 같다면 정상 | ||
if alpha == skill[skill_idx]: | ||
# 다음 선행 스킬을 검사합니다. | ||
skill_idx += 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 포인터가 가르키는 스킬이 결국에는 다른 선행스킬보다 먼저 나와야 한다가 핵심인 풀이네요! |
||
|
||
# 만약 다르다면 비정상 인터럽트 | ||
else: | ||
interrupt = True | ||
break | ||
|
||
# 인터럽트가 진행되지 않았다면 정상적으로 검사 완료 | ||
if not interrupt: | ||
answer += 1 | ||
|
||
return answer |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
구현 로직 자체가 직관적이어서 빠르게 이해할 수 있었어요! 고생하셨습니다 우열님 👍👍👍