278. First Bad Version - easy

一看就知道是binary search的题。
非常简单,没什么好说的。
代码:

/* 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 start = 1, end = n;
        while(start != end){
            int mid = (end-start)/2 + start;
            if (isBadVersion(mid))
                end = mid;
            else 
                start = mid + 1;
        }
        return start;
    }   
}

你可能感兴趣的:(278. First Bad Version - easy)