C++, binary_search


  • 1
    O
     vector<int> searchRange(vector<int>& nums, int target)
        {
            if (!binary_search(nums.begin(), nums.end(), target))
                return {-1, -1};
                
            auto low = lower_bound (nums.begin(), nums.end(), target);
            auto up = upper_bound (nums.begin(), nums.end(), target);    
            
            return {low - nums.begin(), up - nums.begin() - 1};
        }

Log in to reply
 

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