반응형
문제 : https://www.hackerrank.com/challenges/queue-using-two-stacks/problem
해결 코드 :
6문제 time limit 나옴 ㅠㅠ (6/15)
stack1 = []
stack2 = []
def enque(num):
stack1.append(num)
def deque() :
#pop from stack1
#push to stack2
while len(stack1) :
stack2.append(stack1.pop())
#deque
stack2.pop()
#reset
while len(stack2) :
#pop from stack2
#push to stack1
stack1.append(stack2.pop())
def printFront():
print(stack1[0])
n = int(input())
for _ in range(n):
query = list(map(int, input().split()))
if query[0] == 1: #enqueue end
enque(query[1])
elif query[0] == 2: #dequeue front
deque()
elif query[0] == 3: #print front
printFront()
반응형