summaryrefslogtreecommitdiff
path: root/2020/08/22/README.md
blob: 1a464dea1524b64353c5138794f3b8edb9bcdce9 (plain)
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
│   Implement a class for a stack that supports all the regular
│functions
│   (push, pop) and an additional function of max() which returns
│the
│   maximum element in the stack (return None if the stack is
│empty). Each
│   method should run in constant time.
│class MaxStack:
│  def __init__(self):
│    # Fill this in.
│  def push(self, val):
│    # Fill this in.
│  def pop(self):
│    # Fill this in.
│  def max(self):
│    # Fill this in.
│s = MaxStack()
│s.push(1)
│s.push(2)
│s.push(3)
│s.push(2)
│print s.max()
│# 3
│s.pop()
│s.pop()
│print s.max()
│# 2