leetcode_search_for_a_range 发表于 2016-12-02 难度:Medium 解题思路:一个low,一个high,分别从数组的首尾往中心走,查找target。 代码如下: 1234567891011121314151617class Solution {public: vector<int> searchRange(vector<int>& nums, int target) { int low = 0; int high = nums.size()-1; while(low <= high && low <= nums.size()-1 && high >= 0) { if(nums[low] == target && nums[high] == target) return {low,high}; if(nums[low] != target) low++; if(nums[high]!=target) high--; } return {-1,-1}; }}; 运行结果:9ms,超过40.86%