-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy path19.py
48 lines (39 loc) · 1000 Bytes
/
19.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
48
# -*- coding:utf-8 -*-
class Solution:
def __init__(self):
self.a = []
self.b = []
self.count = 0
def push(self, node):
# write code here
if self.count == 0:
self.b.append(node)
self.count += 1
elif node < self.b[-1]:
self.b.append(node)
self.count += 1
else:
self.b.append(self.b[-1])
self.count += 1
self.a.append(node)
def pop(self):
# write code here
r = self.a[-1]
self.a.pop()
self.b.pop()
self.count -= 1
return r
def top(self):
# write code here
return self.a[-1]
def min(self):
# write code here
return self.b[-1]
a = ["PSH3", "MIN", "PSH4", "MIN", "PSH2", "MIN", "PSH3", "MIN", "POP", "MIN", "POP", "MIN", "POP", "MIN", "PSH0",
"MIN"]
s = Solution()
for item_a in a:
s.push(item_a)
for i in range(len(a)):
print s.min()
s.pop()