[LintCode] 第一个错误的代码版本
1 /** 2 * class VersionControl { 3 * public: 4 * static bool isBadVersion(int k); 5 * } 6 * you can use VersionControl::isBadVersion(k) to judge whether 7 * the kth code version is bad or not. 8 */ 9 class Solution { 10 public: 11 /** 12 * @param n: An integers. 13 * @return: An integer which is the first bad version. 14 */ 15 int findFirstBadVersion(int n) { 16 // write your code here 17 int l = 1, r = n; 18 while (l < r) { 19 int m = (l + r) / 2; 20 if (VersionControl::isBadVersion(m)) r = m; 21 else l = m + 1; 22 } 23 return l; 24 } 25 };