zoukankan      html  css  js  c++  java
  • 278. First Bad Version

    You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad.

    Suppose you have n versions [1, 2, ..., n] and you want to find out the first bad one, which causes all the following ones to be bad.

    You are given an API bool isBadVersion(version) which will return whether version is bad. Implement a function to find the first bad version. You should minimize the number of calls to the API.

    题目含义:给定一系列版本号,要求找出第一个出错的版本号。(其中,当前的版本是基于前一个版本的,一旦某个版本出错,则当前版本后续的版本都会出错)

     1     public int firstBadVersion(int n) {
     2         int left=0,right = n-1;
     3         while (left<right)
     4         {
     5             int mid = left + (right-left)/2;
     6             if (isBadVersion(mid+1)) right = mid;
     7             else left = mid+1;
     8         }
     9         return left+1;        
    10     }
  • 相关阅读:
    俩人搞对象,山上骑马
    历史不会偏袒任何一个缺乏正义、良知的人。
    力量和对力量的控制
    超级管理员
    电信F412
    prim算法
    Maven pom.xml配置详解
    PorterDuffXfermode的用法
    使用MaskFilter
    Android drawText获取text宽度的三种方式
  • 原文地址:https://www.cnblogs.com/wzj4858/p/7723668.html
Copyright © 2011-2022 走看看