-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Open
Description
Bug Report for https://neetcode.io/problems/minimum-stack
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
Solution:
class MinStack:
storage: List[int] = []
_min_idx: List[int] = []
def __init__(self):
pass
def push(self, val: int) -> None:
self.storage.append(val)
if not self._min_idx or self._min_idx[-1] > val:
self._min_idx.append(val)
else:
self._min_idx.append(self._min_idx[-1])
def pop(self) -> None:
self.storage.pop()
self._min_idx.pop()
def top(self) -> int:
return self.storage[-1]
def getMin(self) -> int:
return self._min_idx[-1]Test cast:
["MinStack", "push", -1, "push", 3, "push", -4, "getMin", "pop", "getMin", "top"]
Output upon submission:
[null,null,null,null,-4,null,-2,3]
Output upon selecting test case and running:
[null,null,null,null,-4,null,-1,3]
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels