Untitled
unknown
plain_text
a year ago
643 B
1
Indexable
Never
class Solution { public: vector<int> searchRange(vector<int>& arr, int t) { int s=0,e=arr.size()-1; int oc=-1,mid=0; while(s<=e){ mid= s+(e-s)/2; if(arr[mid]==t) { oc=mid; break; } if(arr[mid] < t) s=mid+1; else e=mid-1; } vector<int> res(2,-1); if(oc==-1) return res; int f=oc,l=oc; while(f>=0 && arr[f]==t){ f--; } while(l<arr.size() && arr[l]==t){ l++; } res[0]=f+1; res[1]=l-1; return res; } };