vector<int> searchRange(vector<int>& nums, int target) { if(nums.empty()) return {-1,-1}; int index=binarySearch(nums,target,0,nums.size()-1); if(index==-1) return {-1,-1}; int left=index; int right=index;
int binarySearch(vector<int>& nums,int target,bool findLeft) { int left=0; int right=nums.size()-1; int ans=nums.size(); while(left<=right) { int mid=(left+right)/2; if(nums[mid]>target||(findLeft&&nums[mid]>=target)) { right=mid-1; ans=mid; } else{ left=mid+1; }
} return ans; }
vector<int> searchRange(vector<int>& nums, int target) { if(nums.empty()) return {-1,-1}; int left=binarySearch(nums,target,true); int right=binarySearch(nums,target,false)-1; //cout<<left<<" "<<right<<endl; if(left<nums.size()&&right<nums.size()&&nums[left]==nums[right]) return {left,right}; return {-1,-1}; }