First Bad Version
来源:互联网 发布:社交网络的好处知乎 编辑:程序博客网 时间:2024/06/05 01:02
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.
相当于查找第一个大于等于某个数的位置。
class Solution {public: int firstBadVersion(int n) { int left = 1, right = n ; while(left < right){ int middle = left + (right - left) /2 ; if(isBadVersion(middle)) right = middle; else left = middle+1; } return left; }};
0 0
- [刷题]First Bad Version
- first bad version
- First Bad Version
- [leetcode]First Bad Version
- First Bad Version
- LeetCode First Bad Version
- [leetcode] First Bad Version
- 278 First Bad Version
- 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
- First Bad Version
- #leetcode#First Bad Version
- First Bad Version
- [树形DP FWT] HDU 5909 Tree Cutting
- servlet编程
- hdu 2126 求方案数
- session的使用方法及实例
- Java语言
- First Bad Version
- Android Material Design Toolbar
- POJ 1325 Machine Schedule
- PMOS管学习应用
- 霍夫曼编码 zoj 2339 Hyperhuffman
- 解决mariadb数据库服务无法开启
- BeautifulSoup安装以及一些错误
- jvm运行机制
- Andriod Service与Thread的区别