sharing a somewhat cheating solution


  • 1
    B

    Since the problem requires us to implement binary search...... just post for reference.

     vector<int> searchRange(vector<int>& nums, int target) {
            vector<int> res(2, -1);
            if(find(nums.begin(), nums.end(), target)==nums.end())
                return res;
            auto low=lower_bound(nums.begin(), nums.end(), target);
            auto high=upper_bound(nums.begin(), nums.end(), target);
            res[0]=(int)(low-nums.begin());
            res[1]=(int)(high-nums.begin())-1;
            return res;
        }

Log in to reply
 

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