278. First Bad Version
Given n = 5, and version = 4 is the first bad version.
call isBadVersion(3) -> false
call isBadVersion(5) -> true
call isBadVersion(4) -> true
Then 4 is the first bad version.# The isBadVersion API is already defined for you.
# @param version, an integer
# @return a bool
# def isBadVersion(version):
class Solution(object):
def firstBadVersion(self, n):
"""
:type n: int
:rtype: int
"""
i , j = 1, n
while i <= j:
mid = i + (j - i >> 1)
if isBadVersion(mid):
j = mid - 1
else:
i = mid + 1
return iLast updated
Was this helpful?