문제https://school.programmers.co.kr/learn/courses/30/lessons/42626?language=python3 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 해설최소 힙을 활용하는 문제이다. import heapqdef solution(scoville, K): heapq.heapify(scoville) answer = 0 while scoville[0]
문제https://leetcode.com/problems/delete-greatest-value-in-each-row/ 해설2차원 상태의 배열에서 최대 힙을 적용하는 문제이다. Solution 1.아래는 heap을 이용하여 해결한 방식이다. import heapqclass Solution: def deleteGreatestValue(self, grid: List[List[int]]) -> int: answer = 0 while len(grid[0]) != 0: matrix = [] deleted_comp = [] for row in grid: row = [c if c Solution 2..
문제https://www.acmicpc.net/problem/2075 해설최소 힙을 사용하여 해결하는 문제이다. 공간복잡도를 고려해야하는 문제이므로 모든 데이터를 입력받은 후 pop을 진행하는 것이 아닌 input 과정 중 필요한 공간만큼만 사용하는 것이 핵심이었다. # PyPy3import heapqdef solution(cnt): heap = [] for _ in range(cnt): for v in list(map(int, input().split())): heapq.heappush(heap, v) if len(heap) == cnt+1: heapq.heappop(heap) return heapq.heap..