heap2 [python] 이중우선순위큐 문제 출처 이중우선순위큐 풀이 def solution(operations): answer = [] for op in operations: cmd, num = op.split() if cmd == 'I': answer.append(int(num)) else: if not answer: continue if num == '1': answer.pop(answer.index(max(answer))) else: answer.pop(answer.index(min(answer))) if answer: return [max(answer), min(answer)] else: return [0, 0] 2019. 10. 14. [python] 디스크 컨트롤러 문제 출처 디스크 컨트롤러 풀이 def solution(jobs): num_jobs = len(jobs) answer = 0 jobs.sort(key=lambda x: (x[0], x[1])) start, time = jobs.pop(0) end = time+start answer += time while jobs: nxt_idx = 0 for idx in range(1, len(jobs)): if jobs[idx][0] > end: break else: if jobs[idx][1] < jobs[nxt_idx][1]: nxt_idx = idx nxt = jobs.pop(nxt_idx) if nxt[0] 2019. 10. 13. 이전 1 다음