Posted on

Description

Submission

class Solution {
public:
    vector<int> searchRange(vector<int>& nums, int target) {
        if(nums.empty()) return {-1, -1};
        auto lb = lower_bound(nums.begin(), nums.end(), target);
        if(lb == nums.end() || *lb != target) return {-1, -1};
        for(int i = static_cast<int>(lb - nums.begin()); i < nums.size(); ++i) {
            if(nums[i] != target) return {static_cast<int>(lb - nums.begin()), i - 1};
        }
        return {static_cast<int>(lb - nums.begin()), static_cast<int>(nums.size() -  1)};
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *