Finish problem 0278-first-bad-version

This commit is contained in:
Johan Sandoval
2026-07-22 21:02:15 -05:00
parent d1fefee020
commit 730596f416
2 changed files with 31 additions and 0 deletions
@@ -0,0 +1,14 @@
def isBadVersion(version: int) -> bool:
raise NotImplementedError
class Solution:
def firstBadVersion(self, n: int) -> int:
lo, hi = 1, n
while lo < hi:
check = (hi + lo) // 2
if isBadVersion(check):
hi = check
else:
lo = check + 1
return lo
@@ -0,0 +1,17 @@
import pytest
import solution
from solution import Solution
@pytest.mark.parametrize(
"n,bad",
[
(5, 4),
(1, 1),
(10, 1),
(10, 10),
],
)
def test_first_bad_version(n, bad, monkeypatch):
monkeypatch.setattr(solution, "isBadVersion", lambda v: v >= bad)
assert Solution().firstBadVersion(n) == bad