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 ...
随机推荐
- Leetcode 12
//日积月累,水滴石穿class Solution { public: string longestCommonPrefix(vector<string>& strs) { if ...
- 前序+中序->后序 中序+后序->前序
前序+中序->后序 #include <bits/stdc++.h> using namespace std; struct node { char elem; node* l; n ...
- timer Compliant Controller project (1)--Product introduction meeting
Last week ,I lead the meeting for new project. i'm very excited. The meeting is divided into the fo ...
- Alpha阶段敏捷冲刺---Day2
一.Daily Scrum Meeting照片 PS:不要问我们为什么少了个人,某位不愿说出姓名的大佬强行申请要拍照 二.今天冲刺情况反馈 今天我们依旧在五社区五号楼719进行我们的每日立会.经过昨天 ...
- BZOJ2124: 等差子序列(树状数组&hash -> bitset 求是否存在长度为3的等差数列)
2124: 等差子序列 Time Limit: 3 Sec Memory Limit: 259 MBSubmit: 2354 Solved: 826[Submit][Status][Discuss ...
- BZOJ3298: [USACO 2011Open]cow checkers(佐威夫博弈)
3298: [USACO 2011Open]cow checkers Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 195 Solved: 96[S ...
- BZOJ2938: [Poi2000]病毒(AC自动机)
2938: [Poi2000]病毒 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1678 Solved: 849[Submit][Status][D ...
- Tomcat启动 Unable to process Jar entry [javassist/XXXXXX.class]
例如: 03-Mar-2017 17:01:45.864 SEVERE [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.startup.Co ...
- 新手,Visual Studio 2013 配置Boost库,如何编译和选择
QuantLib installation in VC++ 2010 and later 参考:http://quantlib.org/install/vc10.shtml 1,到官网下载最新的boo ...
- python学习(二)—简明python教程
2016-04-14 20:55:16 八.模块 简介 前面介绍了如何在程序中定义一次函数而重用代码.在其他程序中重用很多函数,就需要使用模块.模块基本上就是一个包含了所有你定义的函数和变量的文件.模 ...