int guessNumber(int n){ int num = 1+(n-1)/2; int left=1,right=n; while(1) { int ret = guess(num); if(ret == 1) left=num+1; else if(ret == -1) right=num-1; else return num; num = left+ (right-left)/2; } }
int guessNumber(int n){ int num = 1+(n-1)/2; int left=1,right=n; while(1) { int ret = guess(num); if(ret == 1) left=num+1; else if(ret == -1) right=num-1; else return num; num = left+ (right-left)/2; } }