forked from illuz/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAC_STL_logn.cpp
37 lines (32 loc) · 853 Bytes
/
AC_STL_logn.cpp
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
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: AC_STL_logn.cpp
* Create Date: 2015-01-27 10:57:52
* Descripton: STL: lower_bound & upper_bound
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 0;
class Solution {
public:
vector<int> searchRange(int A[], int n, int target) {
int* lower = lower_bound(A, A + n, target);
int* upper = upper_bound(A, A + n, target);
if (*lower != target)
return vector<int> {-1, -1};
else
return vector<int>{lower - A, upper - A - 1};
}
};
int main() {
int A[100], n, tar;
Solution s;
while (cin >> n) {
for (int i = 0; i < n; i++)
cin >> A[i];
cin >> tar;
vector<int> res = s.searchRange(A, n, tar);
cout << res[0] << ' ' << res[1] << endl;
}
return 0;
}