-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path34.cpp
More file actions
36 lines (34 loc) · 676 Bytes
/
Copy path34.cpp
File metadata and controls
36 lines (34 loc) · 676 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
vector<int> searchRange(vector<int>& nums, int target) {
vector<int> result(2, -1);
if(nums.size() == 0)
return result;
int ll = 0, lr = nums.size() - 1, mid;
while(ll <= lr){
mid = (ll + lr) / 2;
if(nums[mid] < target)
ll = mid + 1;
else
lr = mid - 1;
}
int rl = 0, rr = nums.size() - 1;
while(rl <= rr){
mid = (rl + rr) / 2;
if(nums[mid] <= target)
rl = mid + 1;
else
rr = mid - 1;
}
if(ll <= rr){
result[0] = ll;
result[1] = rr;
}
return result;
}
};
int main(){
}