First Bad Version

O(logN)

/**
 * public class SVNRepo {
 *     public static boolean isBadVersion(int k);
 * }
 * you can use SVNRepo.isBadVersion(k) to judge whether
 * the kth code version is bad or not.
*/
class Solution {
    /**
     * @param n: An integers.
     * @return: An integer which is the first bad version.
     */
    public int findFirstBadVersion(int n) {
        // write your code here
        int start = 1;
        int end = n;
        while (start + 1 < end) {
            int mid = start + (end - start) / 2;
            if (SVNRepo.isBadVersion(mid)) {
                end = mid;
            } else {
                start = mid;
            }
        }

        if (SVNRepo.isBadVersion(start)) {
            return start;
        }

        if (SVNRepo.isBadVersion(end)) {
            return end;
        }

        return -1;
    }
}
时间: 2024-08-03 19:44:43

First Bad Version的相关文章

maven -- 问题解决(三)Java compiler level does not match the version of the installed Java project facet

问题: Java compiler level does not match the version of the installed Java project facet 解决方法如下: properties->Java Compiler,修改JDK版本,然后Apply

异常:Unsupported major.minor version 52.0 (Use --stacktrace to see the full trace)

异常:Unsupported major.minor version 52.0 (Use --stacktrace to see the full trace) 正在写一个功能,更新了同事提交的代码之后,出现了如下错误: 1 Fatal error during compilation org.apache.tools.ant.BuildException: java.lang.UnsupportedClassVersionError: org/elasticsearch/index/query

How to Downgrade VMware ESXi 5.5 Virtual Machine Hardware Version to 9 from 10

Shut down the virtual machine in the vSphere client. Remove your virtual machine from the ESXi inventory. Browse your Datastore and find the virtual machine's .vmx file.   Download it to your desktop. Open the .vmx file in Notepad or your favorite te

This version of MySQL doesn&#39;t yet support &#39;LIMIT &amp; IN/ALL/ANY/SOME subquery&#39; 错误解决

原因是内层select语句带有limit子句. 原: update stu_score_childen A  set  A.fScore='-1' where  A.fID in (select B.fID from stu_score_childen B limit 0,50 ) 更改后的 update stu_score_childen A  set  A.fScore='-1' where  A.fID in (select C.fID from (select B.fID from st

[LeetCode] Compare Version Numbers

Question: Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0. You may assume that the version strings are non-empty and contain only digits and the . character.The 

This version of the rendering library is more recent than your version of IntelliJ IDEA.

今天往idea里导入其他项目时又遇到了一个问题,单独标记一下. 导入后打开一个布局xml文件,发现不能渲染,报错为: This version of the rendering library is more recent than your version of IntelliJ IDEA. Please update IntelliJ IDEA 看字面意思就是idea的渲染库版本不对,让你升级idea.因为之前升级过android sdk,就想到了以前eclipse的老问题:adt的升级.难

eclipse中,项目有红叉之-Cannot change version of project facet Dynamic Web Module to 3.1

1.打开Problems查看错误原因Window->Show View->Other->General->Problems 2.查看问题 3.发现是Cannot change version of project facet Dynamic Web Module to 3.1 4.根据2里截图的Resource,得到是哪个项目,项目右击->Properties->Project Faces->Dynamic Web Module,更据相应Dynamic Web M

Type Java compiler level does not match the version of the installed Java project facet.项目内容没错但是项目上报错,不影响运行

1.Window->Show View->Problems 2.在项目上右键properties->project Facets->修改右侧的version  保持一致 3.window->preferences->Java->Compiler->设置右侧的Compiler compliance level 4.window->preferences->java->Installed JREs->设置或者选择右侧的Installed

cassandra的schema version, gossip_generation 和host id

这是cassandra里面很重要的三个值; schema version是cassandra cluster里每个node的schema版本,什么叫版本呢?因为cassandra是无中心化的,所以你很难知道所有的node上的schema是否是一致的.你不可能每次把所有的schema都拿了去比较一次.这样很不高效.所以cassandra里就有了schema version这个概念.每次执行DDL操作的时候,都会新生成一个新的schema version, 当这个DDL操作复制到其他node的时候,

[转]解决Cannot change version of project facet Dynamic web module to 2.5

我们用Eclipse创建Maven结构的web项目的时候选择了Artifact Id为maven-artchetype-webapp,由于这个catalog比较老,用的servlet还是2.3的,而一般现在至少都是2.5,在Project Facets里面修改Dynamic web module为2.5的时候就会出现Cannot change version of project facet Dynamic web module to 2.5,如图: 其实在右边可以看到改到2.5需要的条件以及有