LintCode-剑指Offer-(61)搜索区间

来源:互联网 发布:vue js 编辑:程序博客网 时间:2024/06/06 05:35
class Solution {    /**    *@param A : an integer sorted array    *@param target :  an integer to be inserted    *return : a list of length 2, [index1, index2]    */public:    vector<int> searchRange(vector<int> &A,int target) {        // write your code here        int start = -1;        int end = -1;        for (int i = 0;i<A.size();i++){            if (A[i]==target&&start==-1)                start = i;            if (A[i]==target&&start!=-1)                end = i;            if (A[i]!=target&&start!=-1&&end!=-1)break;        }        vector<int> r;        r.push_back(start);        r.push_back(end);        return r;    }};
0 0
原创粉丝点击