분류 전체보기265 [알고리즘] 프로그래머스 | 이중우선순위큐 이중우선순위큐 답: 더보기 힙 하나로 구현하기 from heapq import heappush, heappop def solution(operations): heap = [] for operate in operations: o = operate.split(" ") alpha, num = o[0], int(o[1]) if alpha == "I": heappush(heap, num) elif alpha == "D": if heap and num == -1: heappop(heap) elif heap and num == 1: heap.pop() if len(heap) > 0: return [max(heap), heap[0]] return [0,0] min_heap, max_heap으로 구현하기 from hea.. 2023. 10. 27. [알고리즘] 프로그래머스 | 달리기경주 달리기 경주 답: 더보기 def solution(players, callings): player = {} # 이름 : 등수 ranking = {} # 등수 : 이름 for i, p in enumerate(players): player[p] = i ranking[i] = p for call in callings: idx = player[call] pre_idx = idx-1 pre_call = ranking[pre_idx] ranking[pre_idx], ranking[idx] = call, pre_call player[pre_call], player[call] = idx, pre_idx answer = sorted(player, key=lambda x : player[x]) return answer 문제.. 2023. 10. 24. [알고리즘] 프로그래머스 | 카드뭉치, 공원 산책 보호되어 있는 글 입니다. 2023. 10. 21. [알고리즘] DFS, BFS | 백준 7576 토마토, 프로그래머스 네트워크 보호되어 있는 글 입니다. 2023. 10. 15. 이전 1 ··· 3 4 5 6 7 8 9 ··· 67 다음