-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmax_elem_stack.py
47 lines (25 loc) · 959 Bytes
/
max_elem_stack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# https://www.hackerrank.com/challenges/maximum-element/problem
class Stack:
def __init__(self):
self.MaxStack = [0]
self.curMax = 0
def push(self,val):
self.curMax = max(val,self.curMax)
self.MaxStack.append(self.curMax)
def pop(self):
del self.MaxStack[-1]
self.curMax = self.MaxStack[-1]
def prints(self):
print(self.curMax)
if __name__ == '__main__':
myStack = Stack()
N = int(input().strip())
for _ in range(N):
temp = input().split()
if temp[0]=='3':
myStack.prints()
if temp[0]=='1':
val = int(temp[1])
myStack.push(val)
if temp[0]=='2':
myStack.pop()