Created
October 12, 2021 05:12
-
-
Save stellaqx/5dba75b4d02872ec9ef871814517410b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* class SVNRepo { | |
* public: | |
* static bool isBadVersion(int k); | |
* } | |
* you can use SVNRepo::isBadVersion(k) to judge whether | |
* the kth code version is bad or not. | |
*/ | |
class Solution { | |
public: | |
/** | |
* @param n: An integer | |
* @return: An integer which is the first bad version. | |
*/ | |
int findFirstBadVersion(int n) { | |
int start = 1, end = n; | |
while(start + 1 < end) { | |
int mid = start + (end - start ) / 2; | |
if (SVNRepo::isBadVersion(mid)) { | |
end = mid; | |
} else { | |
start = mid; | |
} | |
} | |
if (SVNRepo::isBadVersion(start)) return start; | |
return end; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment