题目描述:有一个排好序的数组,例如:[1,2,3,4,5,6,7,8,9],现在将这个数组左移五位变成—[6,7,8,9,1,2,3,4,5],现在用这个得到的数组求其中任意数字的下标,例如求6的下标,返回0,要求算法的复杂度为logn。
解题方法:1.使用二分法找到断点的位置;2.从这个断点的位置开始,寻找这个数字,然后哦找到之后%size,就得到了现在这个数字的下标。
#include <iostream>
#include <vector>
using namespace std;
int findBreakPoint(const vector<int> &src)
{
int left = 0, right = src.size() - 1;
int mid;
while