sharing a somewhat cheating solution

  • 1

    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);
            return res;

Log in to reply

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