编程语言
首页 > 编程语言> > leetcode-python-第一个错误版本

leetcode-python-第一个错误版本

作者:互联网

画一个列表自己试试,二分法

# The isBadVersion API is already defined for you.
# @param version, an integer
# @return an integer
# def isBadVersion(version):

class Solution:
    def firstBadVersion(self, n):
        """
        :type n: int
        :rtype: int
        """
        start = 1
        end = n
        while start < end:
            mid = (start + end)//2
            if isBadVersion(mid):
                end = mid
            else:
                start = mid + 1
        return start

 

标签:end,python,isBadVersion,mid,start,int,version,版本,leetcode
来源: https://www.cnblogs.com/cbachen/p/14855640.html