First,This question has some problems itself:the function of guess() returns 0,-1,1,which is refered to equal,higher and lower,but not suited to the discribed ones.

Moreover,some solutions haven't considered the periphery.I got the complete one below.

```
int guess(int num);
class Solution {
public:
int guessNumber(int n) {
if(n<1)
return 0;
if(n==1)
return 1;
long left=1,right=n,flag,mid;
int guess(int num);
while(left<right)
{
mid=(right+left)/2;
flag=guess(mid);
if(flag==0)
return mid;
if(flag==-1)
{
right=mid;
if(left+1==right)
return mid=left;
}
if(flag==1)
{
left=mid;
if(left+1==right)
return mid=right;
}
}
return mid;
}
};
```