diff options
| author | mo khan <mo.khan@gmail.com> | 2020-08-22 15:26:06 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-08-22 15:26:06 -0600 |
| commit | 64b0dd164b5f6c0ff067ba2ed399284f82f890f9 (patch) | |
| tree | 9800332c2e4b2340ff064d4ef3bada00a244062c | |
| parent | 6c064009fc576a4527e9a9629de3ad6b89cbf6f6 (diff) | |
Add problem of the day
| -rw-r--r-- | 2020/08/22/README.md | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/2020/08/22/README.md b/2020/08/22/README.md new file mode 100644 index 0000000..1a464de --- /dev/null +++ b/2020/08/22/README.md @@ -0,0 +1,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 |
