
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
큐 2 (실버4) - https://www.acmicpc.net/problem/18258
문제를 풀고 있습니다.
시간 초과가 나는데 어떤 부분을 조정해야할지 감이 오지 않습니다.

작성한 코드 및 에러 메세지
class Node:
def __init__(self, val):
self.val = val
self.next = None
class LinkedList:
def __init__(self):
self.head = None
self.count = 0
def push(self, val):
self.count += 1
if not self.head:
self.head = Node(val)
return
node = self.head
new_node = Node(val)
while node.next:
node = node.next
node.next = new_node
def pop(self):
if self.count == 0:
print(-1)
return
node = self.head
self.head = node.next
self.count -= 1
print(node.val)
def size(self):
print(self.count)
def empty(self):
if self.count == 0:
print(1)
else:
print(0)
def front(self):
if self.count == 0:
print(-1)
return
print(self.head.val)
def back(self):
if self.count == 0:
print(-1)
return
node = self.head
while node.next:
node = node.next
print(node.val)
N = int(input())
linked_list = LinkedList()
for _ in range(N):
input_string = input()
if 'push' in input_string:
command, value = input_string.split()
value = int(value)
linked_list.push(value)
else:
# pop, size, empty, front, back
command = input_string
if command == 'pop':
linked_list.pop()
elif command == 'size':
linked_list.size()
elif command == 'empty':
linked_list.empty()
elif command == 'front':
linked_list.front()
elif command == 'back':
linked_list.back()
