Compare commits
No commits in common. "3f369e1e70d79379357584f4c1c5568acfc69f44" and "345464d0d4f87f1491cbb58c6f3ff376cb3450f7" have entirely different histories.
3f369e1e70
...
345464d0d4
@ -138,23 +138,3 @@ class Roman:
|
|||||||
total += cls.ALL[c]
|
total += cls.ALL[c]
|
||||||
|
|
||||||
return total
|
return total
|
||||||
|
|
||||||
|
|
||||||
class MinStack:
|
|
||||||
def __init__(self):
|
|
||||||
self._v: list[int] = []
|
|
||||||
self._min: list[int] = []
|
|
||||||
|
|
||||||
def push(self, val: int) -> None:
|
|
||||||
self._v.append(val)
|
|
||||||
self._min.append(min(val, self._min[-1] if self._min else val))
|
|
||||||
|
|
||||||
def pop(self) -> None:
|
|
||||||
self._v.pop(-1)
|
|
||||||
self._min.pop(-1)
|
|
||||||
|
|
||||||
def top(self) -> int:
|
|
||||||
return self._v[-1]
|
|
||||||
|
|
||||||
def getMin(self) -> int: # no qa
|
|
||||||
return self._min[-1]
|
|
||||||
|
@ -28,52 +28,3 @@ def test_find_sqrt_ish(n: int, expected: int):
|
|||||||
)
|
)
|
||||||
def test_int_to_roman(n: int, expected: str):
|
def test_int_to_roman(n: int, expected: str):
|
||||||
assert stuff.Roman.i2r(n) == expected
|
assert stuff.Roman.i2r(n) == expected
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
("ops", "expected"),
|
|
||||||
[
|
|
||||||
(
|
|
||||||
(
|
|
||||||
[
|
|
||||||
("new",),
|
|
||||||
("push", -2),
|
|
||||||
("push", 0),
|
|
||||||
("push", -3),
|
|
||||||
("getMin",),
|
|
||||||
("pop",),
|
|
||||||
("top",),
|
|
||||||
("getMin",),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
[
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
-3,
|
|
||||||
None,
|
|
||||||
0,
|
|
||||||
-2,
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test_min_stack(ops: list[tuple[str] | tuple[str, int]], expected: list[int | None]):
|
|
||||||
returned: list[int | None] = []
|
|
||||||
inst: stuff.MinStack | None = None
|
|
||||||
|
|
||||||
for op in ops:
|
|
||||||
if len(op) == 1:
|
|
||||||
if op[0] == "new":
|
|
||||||
inst = stuff.MinStack()
|
|
||||||
returned.append(None)
|
|
||||||
continue
|
|
||||||
|
|
||||||
returned.append(getattr(inst, op[0])())
|
|
||||||
continue
|
|
||||||
|
|
||||||
method, arg = op
|
|
||||||
returned.append(getattr(inst, method)(arg))
|
|
||||||
|
|
||||||
assert returned == expected
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user