# leetcode Guess Number Higher or Lower

### leetcode 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 guess which number I picked.

Every time you guess wrong, I’ll tell you whether the number is higher or lower.

You call a pre-defined API guess(int num) which returns 3 possible results (-1, 1, or 0):

Example:

C++

Java

Python

Leetcode , , , , . permalink.

### 4 thoughts on “leetcode Guess Number Higher or Lower”

1. lou says:

这个算法会超时啊，楼主自己验证过么

• lou says:

计算mid的时候，mid = (up + low) /2; 会超时，改为 low + (up – low ) / 2;就ok了，，

为什么。。。

• 。。。。。。。。。。。肯定验证过啊 你自己问题吧