// 【1, 2, 3, 4, 5】 -> [4, 5, 1, 2, 3] 查找某个元素,返回下标 int findNum(vector<int> &array, int target){ int left = 0; int right = array.size() - 1; while(left <= right){ int mid = left + (right - left) / 2; if(target == array[mid]) return mid; // 右侧升序 if(array[mid] < array[right]){ if(array[mid] < target && target <= array[right]){ left = mid + 1; }else { right =mid - 1; } } // 左侧升序 if(array[left] < array[mid]){ if(array[left] < target && target <= array[mid]){ right = mid - 1; }else { left = mid + 1; } } } return -1; } int main() { vector<int> array={4, 5, 1, 2, 3}; cout << findNum(array, 6); return 0; }