Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* The isBadVersion API is defined in the parent class VersionControl.
- boolean isBadVersion(int version); */
- public class Solution extends VersionControl {
- public int firstBadVersion(int n) {
- int f = 0;
- int b = n-1;
- int ans = 0;
- while (f <= b) {
- int m = (f + b) / 2;
- boolean x = isBadVersion(m+1);
- if (x == true) {
- b = m-1;
- ans = m+1;
- System.out.println(ans);
- } else {
- f = m+1;
- }
- }
- return ans;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement