Skip to content

Latest commit

 

History

History
40 lines (22 loc) · 513 Bytes

278._First_Bad_Version.md

File metadata and controls

40 lines (22 loc) · 513 Bytes

278. First Bad Version

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

难度 : Easy

思路:

根据 search for a range 改的

class Solution(object):
    def firstBadVersion(self, n):
        """
        :type n: int
        :rtype: int
        """
        l, r = 0, n - 1
        while l <= r:
            mid = l + ((r - l) >> 2)
            if not isBadVersion(mid):
                l = mid + 1
            else:
                r = mid - 1
        return l