题解 | #加一#

加一

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};
}
};

全部评论

相关推荐

评论
3
2
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务