(LeetCode)First Bad Version --- 查找坏版本
来源:互联网 发布:机械战警玩具编程 编辑:程序博客网 时间:2024/05/18 02:08
You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad.
Suppose you have n
versions [1, 2, ..., n]
and you want to find out the first bad one, which causes all the following ones to be bad.
You are given an API bool isBadVersion(version)
which will return whether version
is bad. Implement a function to find the first bad version. You should minimize the number of calls to the API.
Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.
Subscribe to see which companies asked this question
解题分析:
查询最早一个坏的版本,利用二分法查找。
# -*- coding:utf-8 -*-__author__ = 'yx'class Solution(object): def firstBadVersion(self, n): left, right = 1, n while left <= right: mid = (left + right) / 2 if isBadVersion(mid): right = mid - 1 else: left = mid + 1 return left
- (LeetCode)First Bad Version --- 查找坏版本
- leetcode 278. First Bad Version-第一个坏版本|二分查找
- leetcode First Bad Version 第一个坏版本
- First Bad Version 第一个坏版本
- 278. First Bad Version-LeetCode(查找第一个最坏版本)
- leetcode_278. First Bad Version 寻找第一个坏的版本,二分查找法
- LeetCode 278 First Bad Version(第一个坏版本)(二分法)(*)
- [LeetCode] First Bad Version - 二分查找
- leetcode---First Bad Version---二分查找
- 【Leetcode】278. First Bad Version【二分查找】
- leetcode 278. First Bad Version 二分查找
- [leetcode]First Bad Version
- LeetCode First Bad Version
- [leetcode] First Bad Version
- [Leetcode]First Bad Version
- Leetcode: First Bad Version
- leetcode First Bad Version
- LeetCode || First Bad Version
- 判断主程序是Windows应用程序还是控制台应用程序
- js中window.location.search的用法和作用。
- TopShelf-(02)服务-01.安装.bat
- Magento: Fatal error: Cannot override final method Mage_Core_Model_Abstract::clearInstance()
- Android 更改纯色背景图片颜色,可实现一张背景圆形图片展示不同颜色
- (LeetCode)First Bad Version --- 查找坏版本
- 要怎样努力,才能成为很厉害的人
- SAP部分支付和剩余支付清账的区别
- Android6.0_r9 CTS 测试 二
- div运动
- Python语言学习讲解三:详解Python中的split()函数的使用方法
- 当file_get_contents或者simplexml_load_file的时候乱码
- 获取用户的IP地址
- 关于 iOS 10 中 ATS 的问题