254. Drop Eggs【LintCode java】
Description
There is a building of n
floors. If an egg drops from the k th floor or above, it will break. If it's dropped from any floor below, it will not break.
You're given two eggs, Find k while minimize the number of drops for the worst case. Return the number of drops in the worst case.
Clarification
For n = 10, a naive way to find k is drop egg from 1st floor, 2nd floor ... kth floor. But in this worst case (k = 10), you have to drop 10 times.
Notice that you have two eggs, so you can drop at 4th, 7th & 9th floor, in the worst case (for example, k = 9) you have to drop 4 times.
Example
Given n = 10
, return 4
.
Given n = 100
, return 14
.
解析:https://blog.csdn.net/shaya118/article/details/40823225
代码如下:
public class Solution {
/**
* @param n: An integer
* @return: The sum of a and b
*/
public int dropEggs(int n) {
// write your code
long times = 1;
if(n == 2)
return 2;
for(long i = 1; i < n; i++){
if((i+1)*i/2 >= n){
times = i;
break;
}
}
return (int)times;
}
}
254. Drop Eggs【LintCode java】的更多相关文章
- 372. Delete Node in a Linked List【LintCode java】
Description Implement an algorithm to delete a node in the middle of a singly linked list, given onl ...
- 451. Swap Nodes in Pairs【LintCode java】
Description Given a linked list, swap every two adjacent nodes and return its head. Example Given 1- ...
- 445. Cosine Similarity【LintCode java】
Description Cosine similarity is a measure of similarity between two vectors of an inner product spa ...
- 433. Number of Islands【LintCode java】
Description Given a boolean 2D matrix, 0 is represented as the sea, 1 is represented as the island. ...
- 423. Valid Parentheses【LintCode java】
Description Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine ...
- 422. Length of Last Word【LintCode java】
Description Given a string s consists of upper/lower-case alphabets and empty space characters ' ', ...
- 420. Count and Say【LintCode java】
Description The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, ...
- 415. Valid Palindrome【LintCode java】
Description Given a string, determine if it is a palindrome, considering only alphanumeric character ...
- 413. Reverse Integer【LintCode java】
Description Reverse digits of an integer. Returns 0 when the reversed integer overflows (signed 32-b ...
随机推荐
- waring L16: uncalled segement ----keil
1.keil中出现waring:uncalled segement 2.waring L16:这个应该是一个waring等级 3. 转载自 wpb3dm 在Keil C中,如果没有显式调用到定义过的 ...
- 关于content-type请求头的说明
Content-Type请求头的作用,用于标记请求体数据的格式,如: 1. Content-Type:application/x-www-form-urlencoded 请求体:b'pwd=123&a ...
- mybatis if 语句嵌套
在使用mybatis的时候,可以在 if 标签下面加上if标签. 比如要对这个sql语句进行改进. select a.* from emp a inner join dept b on a.deptn ...
- React通过dva-model-extend实现 dva 动态生成 model
前言 实现通过单个component 单个router通过相应的标识对应产生不同model实现数据包分离,model namespce将会覆盖基础的Model,其中的model[state|subsc ...
- markdown常用命令(持续整理更新...)
编写使用的工具 VS Code 拥有丰富插件支持的代码编辑器,当然也支持markdown MdEditor一款在线编辑markdown网站 1.标题 示例: # 一级标题 ## 二级标题 ### 三级 ...
- linux 编译安装pureFTP
安装openssl支持 wget -c https://www.openssl.org/source/openssl.org/source/openssl-1.1.0c.tar.gz tar -zxv ...
- 帝国cms伪静态设置方法(收藏)
众所周知,动态页面不利于收录和排名.伪静态可以完美的解决这问题,配合百度云加速CDN,可以让动态页面有静态页面一样快的访问速度. 今天开拓族给大家带来帝国CMS伪静态的详细设置方法. 1.栏目设置为动 ...
- 【Android】添加依赖包
貌似好像不知一种方法,以后有时间再研究,下面是其中的一种方法
- A64 I2S调试
通过A64 的I2S总线与回音消除模块连接,在A64中需要使能并配置daudio功能. Daudio 为A64 的数字音频接口,可配置成i2s/pcm格式标准音频接口. 内核配置在lichee/lin ...
- python学习之文件读写入门(文件读的几种方式比较)
1.文件读写简单实例:(以w写的方式打开一个文件,以r读一个文件) # Author : xiajinqi # 文件读写的几种方式 # 文件读写 f = open("D://test.txt ...