처음에 문제를 확인했을 때 min()과 max()를 이용해서 풀면 될 것 같다는 생각이 가장 먼저 떠올랐는데, operations의 길이가 최대 1,000,000이라 더 효율적인 알고리즘을 사용해야되는 문제인줄 알았다.
근데 그냥 풀린다... 그래서 파이썬으로 풀면 너무 쉬운 문제가 되어버렸다.
def solution(operations):
l = []
for i in operations:
n, num = i.split(" ")
if n == "I": l.append(int(num))
if n == "D" and len(l):
if num == '1': del l[(l.index(max(l)))]
else: del l[l.index(min(l))]
return [0,0] if not len(l) else [max(l),min(l)]