```
// Forward declaration of guess API.
// @param num, your guess
// @return -1 if my number is lower, 1 if my number is higher, otherwise return 0
int guess(int num);
class Solution {
public:
int guessNumber(int n) {
int u = 0;
while (n != 1){
int mid = (n - 1) / 2 + 1;
int x = guess(mid + u);
if (x == 0) return mid + u;
if (x == -1) n = mid - 1;
if (x == 1){
n = n - mid;
u = u + mid;
}
}
return u + 1;
}
};
```