First Bad Version
You can call to help you determine which version is the first
bad one. The details interface can be found in the code’s annotation part.
Example
Given n = :
Note
Please read the annotation in code area to get the correct way to call
isBadVersion in different language. For example, Java is
Challenge
You should call isBadVersion as few as possible.
题解
Python
Java
lower bound 的实现,这里稍微注意下lb 初始化为 0,因为 n 从1开始。ub 和 lb 分别都在什么条件下更新就好了。另外这里并未考虑 的情况。
复杂度分析
二分搜索,O(\log n).