【leetcode】278. First Bad Version
problem
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的更多相关文章
- 【LeetCode】278. First Bad Version 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 二分查找 日期 题目地址:https://leetcode.c ...
- 【easy】278. First Bad Version
有一系列产品,从某个开始其后都不合格,给定一个判断是否合格的函数,找出N个产品中第一个不合格的产品. 正确答案: // Forward declaration of isBadVersion API. ...
- 【LeetCode】165. Compare Version Numbers 解题报告(Python)
[LeetCode]165. Compare Version Numbers 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- 【Leetcode】Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...
- 53. Maximum Subarray【leetcode】
53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...
- 27. Remove Element【leetcode】
27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...
- 【刷题】【LeetCode】007-整数反转-easy
[刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...
- 【刷题】【LeetCode】000-十大经典排序算法
[刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接 000-十大经典排序算法
随机推荐
- 建一个maven项目
建一个普通的maven项目(eclipse) 需要的jar和文件: eclipse :jdk1.8.0_144 maven:apache-maven-3.5.3 进入(下载):http:// ...
- django学习之——我的 Hello World
pycharm 打开django 创建的项目:添加views.py文件 修改 urls.py from django.conf.urls import patterns, include, url f ...
- iOS block 机制
本文要将block的以下机制,并配合具体代码详细描述: block 与 外部变量 block 的存储域:栈块.堆块.全局块 定义 块与函数类似,只不过是直接定义在另一个函数里,和定义它的那个函数共享同 ...
- etymon word air aero aeri aer ag agreement walk joint trick skill chief forget out~1
1● air 2● aero 3● aeri 4● aer 空气 充气 1● ag 做,代理做 =====>agency 1● agr 2● agri 3 ...
- linux下如何添加一个用户并且让用户获得root权限 备用
(2010-12-02 09:58:30) 转载▼ 标签: 帐号 权限 杂谈 分类: Linux 测试环境:CentOS 5.5 1.添加用户,首先用adduser命令添加一个普通用户,命令如下: # ...
- linux下find和grep命令详解
在linux下面工作,有些命令能够大大提高效率.本文就向大家介绍find.grep命令,他哥俩可以算是必会的linux命令,我几乎每天都要用到他们.本文结构如下: find命令 find命令的一般形式 ...
- python vue 项目
http://www.jianshu.com/p/fe74907e16b9 mac 电脑,亲测可以,可以看下开源的写法及思路
- UVa 10795 - A Different Task 对称, 中间状态, 数位DP 难度: 3
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- body中的onload()函数和jQuery中的document.ready()有什么区别?
1.我们可以在页面中使用多个document.ready(),但只能使用一次onload(). 2.document.ready()函数在页面DOM元素加载完以后就会被调用,而onload()函数则要 ...
- python 类方法中参数使用默认值的方法
class A(): __init__(self, **arg): self.__dict__.update(arg) def M(self, config=None, section= ...