1 package day20170206; 2 //LeetCode:374. Guess Number Higher or Lower 3 /* 4 We are playing the Guess Game. The game is as follows: 5 I pick a number from 1 to n. You have to guess which number I picked. 6 Every time you guess wrong, I'll tell you whether the number is higher or lower. 7 You call a pre-defined API guess(int num) which returns 3 possible results (-1, 1, or 0): 8 9 -1 : My number is lower10 1 : My number is higher11 0 : Congrats! You got it!12 Example:13 n = 10, I pick 6.14 15 Return 6.16 */17 public class guessNumber374 {18 /* The guess API is defined in the parent class GuessGame.19 @param num, your guess20 @return -1 if my number is lower, 1 if my number is higher, otherwise return 021 int guess(int num); */22 23 public static int guessNumber(int n) {24 if(guess(1)==0)25 return 1;26 else if(guess(n)==0)27 return n;28 else{29 int left=1,right=n,mid;30 while(left> 1)替换left+(right-left)/2 ,表示不能理解啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊57 public static void main(String[] args) {58 // TODO Auto-generated method stub59 //System.out.println(guessNumber(10));60 System.out.println(guessNumber(2126753390));61 }62 63 }