You are viewing a single comment's thread. Return to all comments →
Really using two stacks:
n=int(input()) stack_in=[] stack_out=[] def transfer(): while stack_in: stack_out.append(stack_in.pop()) for _ in range(n): arr=input().split(' ') if arr[0]=='1': stack_in.append(int(arr[1])) elif arr[0]=='2': if not stack_out: transfer() if stack_out: stack_out.pop() else: if not stack_out: transfer() if stack_out: print(stack_out[-1])
Seems like cookies are disabled on this browser, please enable them to open this website
Queue using Two Stacks
You are viewing a single comment's thread. Return to all comments →
Really using two stacks: