[just-stopyoon] programmers_더 맵게_Python - #25
Open
just-stopyoon wants to merge 1 commit into
Open
Conversation
just-stopyoon
requested review from
jaejunmin408,
mingxoxo,
sangkyu39 and
seungbinpark
January 26, 2025 12:36
mingxoxo
approved these changes
Jan 30, 2025
mingxoxo
left a comment
Member
There was a problem hiding this comment.
import heapq as hq 이렇게 모듈 import 시 별칭으로 사용할 수 있다는 부분을 까먹고 있었는데 상기시킬 수 있어서 좋았습니다 😆
from heapq import ... 로 해도 좋지만 어디에서 가져온 함수인지 명확하게 표시하려면 별칭이 더 좋은 것 같아요!
수고하셨습니다 ~~
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🔗 문제 링크
📰 문제 요약
섞은 음식의 스코빌 지수 = 가장 맵지 않은 음식의 스코빌 지수 + (두 번쨰로 맵지 않은 음식의 스코빌 지수 * 2)
입력
scoville: 모든 음식의 스코빌 지수를 담은 배열 (2 ≤ scoville의 길이 ≤ 1000000)K: 원하는 스코빌 지수 (0 ≤ K ≤ 1000000000)출력
🔓 문제 접근 방식
기본 아이디어
pop을 통해 원소 삭제 해주는 과정 추가사용 알고리즘
💻 구현 방법
scoville리스트를haep으로 변환👍🏻 최종 제출 코드
📝 새로 학습한 내용
파이썬에서 힙 구현
heapq모듈을 통해 최소 힙을 쉽게 구현할 수 있음heapq.heappush(heap, item): 힙에 새 값을 삽입heapq.heappop(heap): 힙에서 가장 작은 값을 제거하고 반환heapq.heapify(list): 리스트를 힙 구조로 변환→ 또한 정직하게
heapq를 계속 쓸 필요 없이,import heapq as hq를 활용하면 보다 간결하게 사용할 수 있다