LeetCode 278 First Bad Version

 

 

LeetCode  278 First Bad Version

 

 

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

int firstBadVersion(int n) {
    int start=1, end=n;
    while(start < end)
    {
        int mid=start+(end-start)/2;
        if(isBadVersion(mid))
            end=mid;
        else
            start=mid+1;
    }
    return start;
}

 

posted @ 2015-11-28 11:07  Walker_Lee  阅读(104)  评论(0编辑  收藏  举报