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