leetcode374
// Forward declaration of guess API.
// @param num, your guess
// @return -1 if my number is lower, 1 if my number is higher, otherwise return 0
int guess(int num); class Solution {
public:
int guessNumber(int n) {
int i=,j=n;
while(i<j){
int mid=i+(j-i)/;
if(guess(mid)==){
return mid;
}else if(guess(mid)==){
i=mid+;
}else{
j=mid;
}
}
return i;
}
};
https://leetcode.com/problems/guess-number-higher-or-lower/#/description
leetcode374的更多相关文章
- 每天一道LeetCode--374. Guess Number Higher or Lower
We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to gues ...
- [Swift]LeetCode374. 猜数字大小 | Guess Number Higher or Lower
We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to gues ...
- LeetCode374 猜数字大小
我们正在玩一个猜数字游戏. 游戏规则如下:我从 1 到 n 选择一个数字. 你需要猜我选择了哪个数字.每次你猜错了,我会告诉你这个数字是大了还是小了.你调用一个预先定义好的接口 guess(int n ...
随机推荐
- 使用80percent开发rails程序:gem的了解。(kaminari)
学习目的: 对一些主要的gem进行学习了解基本功能: 作者的一些答复:(链接) 关于安全配置: 对于配置文件, 安全仅有一点: 不要提交任何敏感信息到服务端. 所以 rails-template 是添 ...
- Tensorflow学习笔记二
现在来开始安装Tensorflow吧 Tensorflow有两种模式, 一种GPU支持, 另外一种仅CPU支持 虚拟机仅有CPU支持, 那就第一种模式吧 有4种途径去安装 virtualenv &qu ...
- 在请求的参数中设置可选值列表为当前职责可访问的所有OU
方法一: 实现此需求的前提之一是为该请求开启多业务实体访问,开启方法 系统管理员->系统管理->并发->程序,进入OAF页面,查询你的并发,然后点更新,选择请求,在业务实体模式下选择 ...
- [转载]字符串匹配的KMP算法
作者: 阮一峰 日期: 2013年5月 1日 字符串匹配是计算机的基本任务之一. 举例来说,有一个字符串"BBC ABCDAB ABCDABCDABDE",我想知道,里面是否包含另 ...
- TStringGrid的Rows索引值 和 Cells的 索引值, Row的赋值
Caption := sgShopList.Rows[sgShopList.RowCount +].CommaText; Caption := sgShopList.Rows[sgShopList.R ...
- OPENCV Linux安装
https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html
- 接口测试Fiddler实战20150921
(写好的文章被不小心删掉了,现在补一篇) 项目背景: 1.接口URL:http://192.168.xx.xx:8080/mserver/rest/ms 2.接口参数:data=xxxxx&k ...
- nginx默认的配置文件详解
# For more information on configuration, see:# * Official English Documentation: http://nginx.org/en ...
- 最新解决 Ubuntu16.04 和 win10 双系统时间同步问题 (设置为 UTC 时间)
最近在电脑上安装了 Ubuntu16.04 和 Win10 双系统, 开机后发现电脑的开机系统出现了问题,不知道怎么搞的总是会出现8个小时的误差,在网上查了好多文章发现网上的大部分方法都是比较过时的 ...
- NameError: name 'picamera' is not defined
/********************************************************************************* * NameError: name ...