Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class StackMax:
- def __init__(self):
- self.arr = []
- def push(self, x):
- self.arr.append(x)
- # def get_length(self):
- # return len(self.arr)
- def pop(self):
- if len(self.arr):
- return self.arr.pop()
- return 'error'
- def get_max(self):
- if len(self.arr):
- return max(self.arr)
- return 'None'
- n = int(input())
- new_stack = StackMax()
- for i in range(n):
- operation = input()
- if operation.startswith('get_max'):
- print(new_stack.get_max())
- elif operation.startswith('push'):
- value = operation.split()[-1]
- new_stack.push(value)
- elif operation.startswith('pop'):
- call_back = new_stack.pop()
- if call_back == 'error':
- print(call_back)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement