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
'Algorithm > BaekJoon' 카테고리의 다른 글
[백준/Python] 1700번 - 멀티탭 스케줄링 (3) | 2023.10.01 |
---|---|
[백준/Python] 16200번 - 해커톤 (0) | 2023.09.30 |
[백준/Python] 7785번 - 회사에 있는 사람 (0) | 2023.09.30 |
[백준/Python] 2164번 - 카드 2 (0) | 2023.09.30 |
[백준/Python] 15988번 - 1, 2, 3 더하기 3 (0) | 2023.09.29 |