본문 바로가기
문제풀이/Programmers

[프로그래머스💯] 코딩테스트 연습 > 힙(HEAP) > 이중우선순위큐

by 서상혁 2020. 1. 26.

<프로그래머스 문제풀이>

<출처 : 프로그래머스(Programmers)>

 


해답)

def solution(operations):
  q = []
  for i in operations:
    if  i[0] == "I":
      q.append(int(i[2:]))
    elif i == "D 1" and len(q)!=0:
      q.pop(q.index(max(q)))
    elif i == "D -1" and len(q)!=0:
      q.pop(q.index(min(q)))
  if len(q) == 0 :
    return [0,0]
  return [max(q), min(q)]

 

풀이) 

 

그냥 문제 말 그대로 조건문만 걸고 풀었습니다.

이중순위 뭐시기로 머리쓰기 귀찮아서 혹시나 하고 해봤는데 바로 되더라구요...

 

출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges

 

728x90

댓글