【Leetcode】Guess Number Higher or Lower II 题目链接: 题目: 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 I picked is higher or lower. ...
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 I picked is higher or lower. However, when you guess a particular number x, and you guess wrong, you pay $x. You win the game when you guess th...
此解法的时间复杂度是O(log n),空间复杂度是O(1)。 publicintguessNumber2(intn){intlow =1;inthigh = n;while(low <= high) {intmid = (high-low)/2+ low;intresult =guess(mid);if(result ==0) {returnmid; }elseif(result ==1) { low = mid +1; }elseif(result ==-1) { high =...
# @param num, your guess # @return -1 if num is higher than the picked number # 1 if num is lower than the picked number # otherwise return 0 # def guess(num: int) -> int: class Solution: def guessNumber(self, n: int) -> int: # 二分区间为 [1, n] l, r = 1, n # ...
Can you solve this real interview question? Guess Number Higher or Lower II - We are playing the Guessing Game. The game will work as follows: 1. I pick a number between 1 and n. 2. You guess a number. 3. If you guess the right number, you win the ga
You have to guess which number I picked. Every time you guess wrong, I&rsqu... LeetCode 374, 375 Guess Number LeetCode 374 这个题目相对还是比较容易的,每次猜了结果之后分成两部分,使用二叉查找的方式来做就可以了。 LeetCode 357 这个题目描述的确实有点不太清楚,看了hint:“The best strategy ...
Every time you guess wrong, I will tell you whether the number I picked is higher or lower than your guess. You call a pre-defined APIint guess(int num), which returns three possible results: -1: Your guess is higher than the number I picked (i.e.num > pick). ...
However, when you guess a particular number x, and you guess wrong, you pay$x. You win the game when you guess the number I picked. Example: n = 10, I pick 8. First round: You guess 5, I tell you that it's higher. You pay $5. ...
技术标签: LeetCodeWe 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 ...
题目地址:https://leetcode.com/problems/guess-number-higher-or-lower/#/description 题目描述 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. ...