4 line solution using C++ STL


  • 0
    M
    class Solution {
    public:
        vector<int> searchRange(vector<int>& nums, int target) {
            auto lb = lower_bound(nums.begin(), nums.end(), target);
            auto ub = upper_bound(nums.begin(), nums.end(), target);
            if (lb == ub) return vector<int> {-1, -1};
            return vector<int> {lb - nums.begin(), ub - nums.begin() - 1};
        }
    };
    

Log in to reply
 

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