Algorithm/BaekJoon
[백준/Python] 10845번 - 큐
빵빵0
2023. 10. 1. 17:12
import sys
from collections import deque
input = sys.stdin.readline
q = deque()
for _ in range(int(input())):
command = input().rstrip()
if command == "pop":
print(-1 if len(q) == 0 else q.popleft())
elif command == "size":
print(len(q))
elif command == "empty":
print(+(not q))
elif command == "front":
print(-1 if len(q) == 0 else q[0])
elif command == "back":
print(-1 if len(q) == 0 else q[-1])
else:
_, num = command.split()
q.append(num)
기본적인 큐 문제다.
empty 명령어, push 명령어를 어떻게 처리했는지 참고하면 좋을듯 하다
시간 복잡도
deque vs list
