Commit 64b0dd1
Changed files (1)
2020
08
22
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