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:

题目地址:leetcode Guess Number Higher or Lower

题意:猜数字,给定一个数n,要你调用guess函数,来判断你猜的n和对方的值是否一样。

思路:就是二分搜索嘛。。。。没什么好说的

C++

Java

Python

 

 

 

 

 

本题是leetcode 374 Guess Number Higher or Lower题解

更多题解可以查看:https://www.hrwhisper.me/leetcode-algorithm-solution/

本博客若无特殊说明则由 hrwhisper 原创发布
转载请点名出处:细语呢喃 > leetcode Guess Number Higher or Lower
本文地址:https://www.hrwhisper.me/leetcode-guess-number-higher-lower/

您的支持将鼓励我继续创作!

Leetcode , , , , . permalink.

4 thoughts on “leetcode Guess Number Higher or Lower

Leave a Reply

Your email address will not be published. Required fields are marked *