美文网首页
74.first bad version

74.first bad version

作者: 博瑜 | 来源:发表于2017-07-03 08:29 被阅读0次
    /**
     * 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;
        else return end;
    }
    }

    相关文章

      网友评论

          本文标题:74.first bad version

          本文链接:https://www.haomeiwen.com/subject/fqkacxtx.html