Question: 374. Guess Number Higher or Lower
Intution:
Time Complexity:
Space Complexity:
Solution:
public class Solution extends GuessGame {
public int guessNumber(int n) {
int low = 1;
int high = n;
while (low < high) {
int mid = low + (high - low) / 2;
if (guess(mid) == 0)
return mid;
else if (guess(mid) == -1)
high = mid - 1;
else
low = mid + 1;
}
return low;
}
}