# 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
"""
if n < 1:
return -1
left=1
right=n
while left + 1 < right:
mid=(left+right)/2
bolBad = isBadVersion(mid)
if bolBad:
right=mid
else:
left=mid
if isBadVersion(left):
return left
elif isBadVersion(right):
return right
return -1
相关文章
- 03-14leetcode first bad version python
- 03-14【leetcode❤python】387. First Unique Character in a String
- 03-14【LeetCode】387. First Unique Character in a String 解题报告(Python)
- 03-14【leetcode】278. First Bad Version
- 03-14278. First Bad Version
- 03-14278. First Bad Version 折半查找,分治法
- 03-14278. First Bad Version
- 03-14LeetCode278:First Bad Version
- 03-14letecode [278] - First Bad Version
- 03-14278. First Bad Version