package leetcode;

/**
 * https://leetcode.com/problems/first-bad-version/
 */
public class Problem278 {
    public static class VersionControl {
        public boolean isBadVersion(int version) {
            if (version <= 4) {
                return true;
            }
            return false;
        }
    }
    
    public static class Solution extends VersionControl {
        public int firstBadVersion(int n) {
            return 0;
        }
    }
    
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.firstBadVersion(10));
    }
}

@@ -218,12 +218,12 @@
 ion 
-%3C= 4
+%3E= 1
 ) %7B%0A
@@ -430,125 +430,477 @@
     
-return 0;%0A        %7D
+int left = 1;%0A            int right = n;
 %0A    
-%7D%0A
     
-%0A
     
-public static void main(String%5B%5D args) %7B%0A        Solution solution = new Solut
+while (left %3C= right) %7B%0A                int mid = (int) (((long) left + (long) right) / 2);%0A                if (isBadVersion(mid)) %7B%0A                    // go left%0A                    right = mid - 1;%0A                %7D else %7B%0A                    // go right%0A                    left = mid + 1;%0A                %7D%0A                if (mid-1 %3E= 1) %7B%0A                    boolean b = isBadVersion(mid-1) %5E isBadVers
 ion(
+mid
 );%0A 
@@ -910,57 +910,369 @@
     
-System.out.println(solution.firstBadVersion(10));
+            if (b) %7B%0A                        return mid;%0A                    %7D%0A                %7D%0A                if (mid+1 %3C= n) %7B%0A                    boolean b = isBadVersion(mid+1) %5E isBadVersion(mid);%0A                    if (b) %7B%0A                        return mid + 1;%0A                    %7D%0A                %7D%0A            %7D%0A            return left;%0A        %7D
 %0A   

Solve problem 278