problem

278. First Bad Version

solution1:遍历;

// Forward declaration of isBadVersion API.
bool isBadVersion(int version); class Solution {
public:
int firstBadVersion(int n) {
int ver = ;
while(ver<n)
{
if(isBadVersion(ver)) return ver;
ver++;
}
return ver;
}
};

solution2:二分法;

// Forward declaration of isBadVersion API.
bool isBadVersion(int version); class Solution {
public:
int firstBadVersion(int n) {
int left = , right = n, mid;
while(left<right)
{
mid = left + (right-left)/;
if(isBadVersion(mid)) right = mid;
else left = mid + ;//err.
}
return left;
}
};

参考

1. Leetcode_278_First Bad Version;

【leetcode】278. First Bad Version的更多相关文章

  1. 【LeetCode】278. First Bad Version 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 二分查找 日期 题目地址:https://leetcode.c ...

  2. 【easy】278. First Bad Version

    有一系列产品,从某个开始其后都不合格,给定一个判断是否合格的函数,找出N个产品中第一个不合格的产品. 正确答案: // Forward declaration of isBadVersion API. ...

  3. 【LeetCode】165. Compare Version Numbers 解题报告(Python)

    [LeetCode]165. Compare Version Numbers 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...

  4. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

  5. 【Leetcode】Pascal&#39;s Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...

  6. 53. Maximum Subarray【leetcode】

    53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...

  7. 27. Remove Element【leetcode】

    27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...

  8. 【刷题】【LeetCode】007-整数反转-easy

    [刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...

  9. 【刷题】【LeetCode】000-十大经典排序算法

    [刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接 000-十大经典排序算法

随机推荐

  1. 一、SQL应用(工作中遇到的根据表的某列的值不同,采用的不同列关联表)

    一.工作总结: 今天工作中遇到了这样一个需求,具体是根据某张表的某一列值得不同,进行不同关联操作.起初自己的想法是采用UNION操作,把两种情况连接起来,但是会出现一个问题,当进行动态传值SQL拼接的 ...

  2. Hadoop格式化 From hu-hadoop1/192.168.11.11 to hu-hadoop2:8485 failed on connection exception: java.net.

    192.168.11.12:8485: Call From hu-hadoop1/192.168.11.11 to hu-hadoop2:8485 failed on connection excep ...

  3. TOR的十个最好的替代工具

    TOR的十个最好的替代工具: 一.Comodo Dragon(基于Chromium) TOR基于Firefox,因为我们换个口味,首先推荐一个基于开源项目Chromium的Comodo Dragon, ...

  4. Python version 2.7, which was not found in the registry

    在安装部分Python包时会出现问题:明明已经安装了Python2.7,但无法在注册表相关位置找不到,那该怎么感觉该问题呢? 首先检查你的系统位数,位数不同,解决方案不一样. 1)32位系统:在cmd ...

  5. Android 音视频深入 四 录视频MP4(附源码下载)

    本篇项目地址,名字是<录音视频(有的播放器不能放,而且没有时长显示)>,求star https://github.com/979451341/Audio-and-video-learnin ...

  6. UVa 11636 - Hello World! 二分,水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  7. day16-python常用的内置模块2

    logging模块的使用 一:日志是我们排查问题的关键利器,写好日志记录,当我们发生问题时,可以快速定位代码范围进行修改.Python有给我们开发者们提供好的日志模块,下面我们就来介绍一下loggin ...

  8. 【资料收集】QT学习资料

    几个专栏 Qt学习之路(3):Hello, world!(续) - 豆子空间 - 51CTO技术博客 http://devbean.blog.51cto.com/448512/194137 Qt 学习 ...

  9. TNetHTTPClient 使用

    unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System ...

  10. git-github-TortoiseGit综合使用教程(一)简介

    简介: 本系列教程将参考廖雪峰的git系列教程,使用github的web界面,和TortoiseGit图形界面windows程序来实现. git 是什么: Git是目前世界上最先进的分布式版本控制系统 ...