Given a sorted array of integers, find the starting and ending position of a given target value.
Your algorithm's runtime complexity must be in the order of O(log n).
If the target is not found in the array, return [-1,
-1].
For example,
Given [5, 7, 7, 8, 8, 10] and target value 8,
return [3, 4].
思路:这道题是binary search的改进版。当寻找到target所在的k位置时,需要判断target的起始索引值和终止索引值。可以这么思考:首先得到k的位置,如果k不存在则返回[-1,-1];如果k存在,则起始的......
阅读全文