/**
* Forward declaration of guess API.
* @param num your guess
* @return -1 if num is lower than the guess number
* 1 if num is higher than the guess number
* otherwise return 0
* int guess(int num);
*/
class Solution {
public:
int guessNumber(int n) {
}
};
/**
* Forward declaration of guess API.
* @param num your guess
* @return -1 if num is lower than the guess number
* 1 if num is higher than the guess number
* otherwise return 0
* func guess(num int) int;
*/
func guessNumber(n int) int {
low, high := 1, n
num := 1
c := 0
for low <= high {
num = (high-low)/2 + low
c = guess(num)
if c == 0 {
return num
} else if c == -1 {
high = num - 1
} else {
low = num + 1
}
}
return num
}