9ms - 7 lines solution in C++


  • 0
    I
    vector<int> searchRange(vector<int>& nums, int target) {
        vector<int> solution(2, -1);
        int low = upper_bound(nums.begin(), nums.end(), target - 1) - nums.begin();
        if (low == nums.size() || nums[low] != target) return solution;
        solution[0] = low;
        int up = upper_bound(nums.begin(), nums.end(), target) - nums.begin();
        solution[1] = up - 1;
        return solution;
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.