diff --git a/leetcode/stuff.py b/leetcode/stuff.py index 0525b95..508338c 100644 --- a/leetcode/stuff.py +++ b/leetcode/stuff.py @@ -143,22 +143,18 @@ class Roman: class MinStack: def __init__(self): self._v: list[int] = [] - self._min: int | None = None + self._min: list[int] = [] def push(self, val: int) -> None: self._v.append(val) - - if self._min is None or self._min > val: - self._min = val + self._min.append(min(val, self._min[-1] if self._min else val)) def pop(self) -> None: - popped = self._v.pop(-1) - - if popped == self._min: - self._min = min(self._v) + self._v.pop(-1) + self._min.pop(-1) def top(self) -> int: return self._v[-1] def getMin(self) -> int: # no qa - return typing.cast(int, self._min) + return self._min[-1]