1. // Forward declaration of guess API.
  2. // @param num, your guess
  3. // @return -1 if my number is lower, 1 if my number is higher, otherwise return 0
  4. int guess(int num);
  5.  
  6. class Solution {
  7. public:
  8. int guessNumber(int n) {
  9. int i=,j=n;
  10. while(i<j){
  11. int mid=i+(j-i)/;
  12. if(guess(mid)==){
  13. return mid;
  14. }else if(guess(mid)==){
  15. i=mid+;
  16. }else{
  17. j=mid;
  18. }
  19. }
  20. return i;
  21. }
  22. };

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. Leetcode 12

    //日积月累,水滴石穿class Solution { public: string longestCommonPrefix(vector<string>& strs) { if ...

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

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

  3. 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 ...

  4. Alpha阶段敏捷冲刺---Day2

    一.Daily Scrum Meeting照片 PS:不要问我们为什么少了个人,某位不愿说出姓名的大佬强行申请要拍照 二.今天冲刺情况反馈 今天我们依旧在五社区五号楼719进行我们的每日立会.经过昨天 ...

  5. BZOJ2124: 等差子序列(树状数组&hash -> bitset 求是否存在长度为3的等差数列)

    2124: 等差子序列 Time Limit: 3 Sec  Memory Limit: 259 MBSubmit: 2354  Solved: 826[Submit][Status][Discuss ...

  6. BZOJ3298: [USACO 2011Open]cow checkers(佐威夫博弈)

    3298: [USACO 2011Open]cow checkers Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 195  Solved: 96[S ...

  7. BZOJ2938: [Poi2000]病毒(AC自动机)

    2938: [Poi2000]病毒 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 1678  Solved: 849[Submit][Status][D ...

  8. 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 ...

  9. 新手,Visual Studio 2013 配置Boost库,如何编译和选择

    QuantLib installation in VC++ 2010 and later 参考:http://quantlib.org/install/vc10.shtml 1,到官网下载最新的boo ...

  10. python学习(二)—简明python教程

    2016-04-14 20:55:16 八.模块 简介 前面介绍了如何在程序中定义一次函数而重用代码.在其他程序中重用很多函数,就需要使用模块.模块基本上就是一个包含了所有你定义的函数和变量的文件.模 ...