题解 | #旋转数组的最小数字#
旋转数组的最小数字
https://www.nowcoder.com/practice/9f3231a991af4f55b95579b44b7a01ba
/** * * @param rotateArray int整型一维数组 * @param rotateArrayLen int rotateArray数组长度 * @return int整型 */ int minNumberInRotateArray(int* arr, int arrSize ) { // write code here /*暴力求解 int i; for(i=1;i<arrSize;++i){ if(arr[0]>arr[i]) arr[0]=arr[i]; } return arr[0]; */ //二分法求解 int left = 0,right = arrSize - 1; int mid; while(left<right){ mid = left + (right-left)/2; if(arr[mid]>arr[right]) left = mid+1; else if(arr[mid]==arr[right]) right -= 1; else right=mid; } return arr[left]; }