[mingxoxo] programmers_더맵게_Python - #23
Open
mingxoxo wants to merge 1 commit into
Open
Conversation
just-stopyoon
approved these changes
Jan 26, 2025
just-stopyoon
left a comment
Contributor
There was a problem hiding this comment.
히히 저랑 풀이가 똑같네요!!
C언어로 풀 때는 연결리스트로 heap을 일일히 구현해줬어야 했는데,, 파이썬은 넘나 편한 것,,,
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.
🔗 문제 링크
https://school.programmers.co.kr/learn/courses/30/lessons/42626
섞은 음식의 스코빌 지수 = 가장 맵지 않은 음식의 스코빌 지수 + (두 번째로 맵지 않은 음식의 스코빌 지수 * 2)💡 풀이 아이디어
heapq 모듈을 사용하여 최소 힙을 사용하였습니다. heapq의 기본 동작은 value 값을 기준으로 최소 힙으로 배열합니다.
scoville리스트를 heapify 함수를 통해 최소 힙으로 재배열 한 후, 리스트에 음식이 2개 이상 있을 경우 모든 음식의 스코빌 지수가 K 이상이 될 때까지 만들어 추가해줍니다.만약 남은 음식이 K 미만의 스코빌 지수를 가질 경우 -1을 반환합니다.
사실 남은 음식이 K 미만일 경우
scoville리스트의 개수가 1개인 경우만 있어 len을 사용해도 되었을 것 같은데, 리스트 원소를 직접 접근해서 사용해주었습니다.📝 새로 학습한 내용
📚 참고 자료