# Search for a Range

class Solution {
public:
vector<int> searchRange(vector<int>& nums, int target) {
vector<int> result;
int tmp = 0;
int left = 0, right = nums.size(), mid = 0;
//if (left == right) return nums[0] == target ? vector<int>{0, 0} : vector<int>{ -1, -1 };
while (left<right){
mid = (left + right) / 2;
if (nums[mid] == target){
tmp = mid;
while (mid>0&&nums[mid - 1] == target) mid--;
while (tmp<nums.size()-1&&nums[tmp + 1] == target) tmp++;
return vector<int> {mid, tmp};
}
else if (nums[mid]<target){
left = mid + 1;
}
else{
right = mid;
}

}
return vector<int> {-1, -1};
}
};

#### LeetCode解题报告--Search for a Range

2015-12-04 13:32:03

#### Search for a Range -- LeetCode

2014-03-06 03:48:49

#### LeetCode 34 — Search for a Range（C++ Java Python）

2014-04-03 20:53:45

#### LeetCode 34 Search for a Range (C,C++,Java,Python)

2015-05-14 21:28:11

#### leetcode 34 -- Search for a Range

2015-06-23 00:36:45

#### leetcode_c++：Search for a Range（034）

2016-05-18 00:45:22

#### leetcode笔记：Search for a Range

2015-12-25 16:59:29

#### [LeetCode34]Search for a Range

2014-06-16 01:31:31

#### lintcode:Search Range in Binary Search Tree

2015-05-16 22:22:15

#### 【LeetCode-面试算法经典-Java实现】【034-Search for a Range（搜索一个范围）】

2015-07-27 07:17:03