/**
* Forward declaration of guess API.
* @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
* int guess(int num);
*/
class Solution {
public:
int guessNumber(int n) {
while(n>0){
int pick=guess(n);
if(pick==0){
return n;
}
else if(pick<0){
n-=1;
}
else
n+=1;
}
return 0;
}
};
LEETCODE 374. 猜数字大小
最新推荐文章于 2024-05-20 21:56:33 发布