/** * Forward declaration of guess API. * (The problem description is not clear, so I translate it into follows.) * * @param traget num * guess num * * @return -1 if guess num > target num * 0 if guess num == target num * 1 if guess num < target num */classSolution{public:intguessNumber(intn){intl=1;intr=n;// Find the first guess num that >= target numwhile(l<r){constintm=l+(r-l)/2;if(guess(m)<=0)// -1, 0r=m;elsel=m+1;}returnl;}};
/** * Forward declaration of guess API. * (The problem description is not clear, so I translate it into follows.) * * @param traget num * guess num * * @return -1 if guess num > target num * 0 if guess num == target num * 1 if guess num < target num */publicclassSolutionextendsGuessGame{publicintguessNumber(intn){intl=1;intr=n;// Find the first guess num that >= target numwhile(l<r){finalintm=l+(r-l)/2;if(guess(m)<=0)// -1, 0r=m;elsel=m+1;}returnl;}}