标签:return color int lower ber for api ati while
1 // Forward declaration of guess API. 2 // @param num, your guess 3 // @return -1 if my number is lower, 1 if my number is higher, otherwise return 0 4 int guess(int num); 5 6 class Solution 7 { 8 public: 9 int guessNumber(int n) 10 { 11 int left=1,right=n,mid=0; 12 while(left<right) 13 { 14 mid=left+(right-left)/2; 15 if(guess(mid)==1) 16 left=mid+1; 17 else if(guess(mid)==-1) 18 right=mid; 19 else 20 return mid; 21 } 22 return left; 23 } 24 };
二分,问题不大
374. Guess Number Higher or Lower
标签:return color int lower ber for api ati while
原文地址:https://www.cnblogs.com/zhuangbijingdeboke/p/9093796.html