278. First Bad Version

https://leetcode.com/problems/first-bad-version/

solution

class Solution:
    def firstBadVersion(self, n: int) -> int:
        return self.bs(1, n)

    def bs(self, l, r):
        while r > l:
            mid = l + (r - l) // 2
            if isBadVersion(mid):
                r = mid
            else:
                l = mid + 1
        return l

时间复杂度:O() 空间复杂度:O()

Last updated