// 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的更多相关文章

  1. 每天一道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 ...

  2. [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 ...

  3. LeetCode374 猜数字大小

    我们正在玩一个猜数字游戏. 游戏规则如下:我从 1 到 n 选择一个数字. 你需要猜我选择了哪个数字.每次你猜错了,我会告诉你这个数字是大了还是小了.你调用一个预先定义好的接口 guess(int n ...

随机推荐

  1. web漏洞扫描工具集合

    最好用的开源Web漏洞扫描工具梳理 链接:www.freebuf.com/articles/web/155209.html 赛门铁克2017年互联网安全威胁报告中提出在他们今年扫描的网站中,有76%都 ...

  2. C# 简单生成双色球代码

    红球篮球产生代码 public class TestD { //产生几组数据 public void getzhu( int num) { ; m < num; m++) { getred(); ...

  3. 前序+中序->后序 中序+后序->前序

    前序+中序->后序 #include <bits/stdc++.h> using namespace std; struct node { char elem; node* l; n ...

  4. checkbox选中的问题(Ajax.BeginForm)

    判断checkbox选中的方法方法一:if ($("#checkbox-id")get(0).checked) { // do something} 方法二:if($('#chec ...

  5. 新书《Cocos2dx 3.x 3D图形学渲染技术讲解》问世

    笔者介绍:姜雪伟,IT公司技术合伙人,IT高级讲师,CSDN社区专家,特邀编辑,畅销书作者,已出版书籍:<手把手教你架构3D游戏引擎>电子工业出版社和<Unity3D实战核心技术详解 ...

  6. Maven的安装学习笔记

    安装 1.下载安装包:http://maven.apache.org/download.cgi 2.检查JDK是否安装,没有安装,先安装JDK cmd中输入:java -version 3.解压后配置 ...

  7. Winform开发之窗体显示、关闭与资源释放

    Winform的窗体涉及到一般窗体(单文档窗体).MDI窗体.窗体之间的关系等,那么如果调用打开新窗体.如何关闭窗体.窗体资源的释放等都关系到软件运行的效率,本文一一介绍 1.窗体的显示 从一个窗体打 ...

  8. Python流程控制-while循环-for循环

    写重复代码 是可耻的行为 -------------- 完美的分割线  -------------- 摘录自:http://www.runoob.com/python/python-loops.htm ...

  9. opencv之批量转换灰度图并保存

    当图片名字有数字规律时,批量处理方式. ①srcImage 图片名字有规律 ②将srcImage文件下的图片,转换为灰度图并保存入grayImage文件夹. ③ #include <iostre ...

  10. Codeforces 133A:HQ9+

    A. HQ9+ time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...