Advertisement
FroztGal

stack_with_max

Jan 11th, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. # Input
  2. q = int(input())
  3.  
  4. # Init
  5. st1 = [-1]
  6. stm = [-1]
  7. res = ''
  8.  
  9. # Main
  10. for i in range(q):
  11.     op = input().rstrip()
  12.     if ' ' in op:
  13.         op = op.split()
  14.         val = int(op[1])
  15.         st1.append(val)
  16.         if val > stm[len(stm)-1]:
  17.             stm.append(val)
  18.         else:
  19.             stm.append(stm[len(stm)-1])
  20.     elif op == 'pop':
  21.         st1.pop()
  22.         stm.pop()
  23.     else:
  24.         res = stm[len(stm)-1]
  25.         # Output
  26.         print(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement