[Leetcode]278. First Bad Version
来源:互联网 发布:mac里面xp升级win7 编辑:程序博客网 时间:2024/05/22 12: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.
// Forward declaration of isBadVersion API.bool isBadVersion(int version);class Solution {public: int firstBadVersion(int n) { int low = 1; int high = n; int mid = 0; while (low < high) { mid = low + (high - low) / 2; if (isBadVersion(mid)) high = mid; else low = mid + 1; } return low; }};
0 0
- 278. First Bad Version LeetCode
- LeetCode 278. First Bad Version
- 【LeetCode】278. First Bad Version
- Leetcode 278. First Bad Version
- leetcode 278. First Bad Version
- LeetCode 278. First Bad Version
- LeetCode *** 278. First Bad Version
- [leetcode] 278. First Bad Version
- LeetCode 278. First Bad Version
- leetcode-278. First Bad Version
- LeetCode 278. First Bad Version
- [Leetcode] 278. First Bad Version
- Leetcode 278. First Bad Version
- [leetcode]278. First Bad Version
- LeetCode 278. First Bad Version
- Leetcode 278. First Bad Version
- LeetCode-278.First Bad Version
- LeetCode - 278. First Bad Version
- LeetCode 347. Top K Frequent Elements
- 欢迎使用CSDN-markdown编辑器
- vs2013 error C3861: “snprintf”: 找不到标识符
- 208. Implement Trie (Prefix Tree)
- 【基础知识思考整理 】MySQLSQL注入(SQL Injection )和防注入
- [Leetcode]278. First Bad Version
- 各种乱七八糟的模板 【不定期补充】[C++语言描述]
- 欧几里得 与 扩展欧几里得
- TabHost
- 天气预报插件
- android MVP模式介绍与实战
- 关于头文件重复包含以及函数重定义问题
- Spark RDD缓存代码分析
- VC课程 第四章 笔记