leetcode278-第一个错误的版本

// Forward declaration of isBadVersion API.
bool isBadVersion(int version);

int firstBadVersion(int n) {
    int high = n;
    int low = 1;
    int mid ;
    int midVer;
    while(low <= high)
    {
        mid = low + (high-low)/2;
        midVer = isBadVersion(mid);
        if (midVer == false)
            low = mid+1;
        else
            high = mid-1;
    }
    return low;
}

 

posted @ 2018-12-01 11:08  xinfenglee  阅读(216)  评论(0编辑  收藏  举报