Nine Chapters count judges Net-original website
http://www.jiuzhang.com/problem/53/
Topics
In the early SVN code controller, the code version number was incremented from 1. One day you submit a bug code to the code base, which causes the unit test on this version to fail Tests. And unfortunately, because everyone who contributes code to this codebase is more independent, and you're on vacation, no one fixes the bug, which results in a single version of the unit test that doesn't work. If you say that the code version number is now N. Find out the first version of the code that went wrong (that is, the bug you submitted).
You can call a function isbadversion (ID) to test if the version number ID is a good version that can be tests through the unit. Your algorithm should call isbadversion this function as little as possible.
Online test
http://lintcode.com/problem/first-bad-version/
Answer
The simple dichotomy method can be used to solve the problem.
Python Code:
Start, end = 1, n
While start + 1 < end:
Mid = (start + end)/2
If Isbadversion (mid):
End = Mid
Else
Start = mid + 1
If Isbadversion (start):
return start
Return end
Nine-chapter algorithm surface question 53 first error code version