You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class Solution {
public:
vector searchRange(vector& nums, int target) {
if(nums.empty()) return vector<int>{-1,-1};
int lower = lower_bound(nums, target);
int upper = upper_bound(nums, target)-1;
//if(nums[lower] != target || lower==nums.size()) return vector<int>{-1,-1};
// there is a trap in this place if we use left open right closed interval
// As lower pointer is possible to be out of the nums vector, nums[lower] may return errors
if (lower == nums.size() || nums[lower] != target) return vector<int>{-1, -1};
return vector<int>{lower, upper};
}
The text was updated successfully, but these errors were encountered:
Sorry I don't understand your question - since in the code we are checking lower == nums.size() before nums[lower] != target, it should be impossible to query out of bound indices?
class Solution {
public:
vector searchRange(vector& nums, int target) {
The text was updated successfully, but these errors were encountered: