题解 | #加一#
加一
http://www.nowcoder.com/practice/4d135ddb2e8649ddb59ee7ac079aa882
class Solution {
public:
/*
*
* @param A int整型一维数组
* @param n int A数组长度
* @param target int整型
* @return int整型vector
*/
vector<int> searchRange(int</int> A, int n, int target) {
int l = lower_bound(A, A + n, target) - A;
int r = upper_bound(A, A + n, target) - A;
if(l == n || A[l] != target)
return {-1, -1};
return {l, r - 1};
}
};
查看17道真题和解析