llllmz

导航

278. 第一个错误的版本c

// The API isBadVersion is defined for you.
// bool isBadVersion(int version);

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

 

posted on 2024-03-13 23:39  神奇的萝卜丝  阅读(17)  评论(0)    收藏  举报