Skip to content

Latest commit

 

History

History
23 lines (18 loc) · 505 Bytes

278. First Bad Version.md

File metadata and controls

23 lines (18 loc) · 505 Bytes

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(log(n))
空间复杂度:O(1)