Untitled
unknown
plain_text
a year ago
676 B
2
Indexable
Never
class Solution { public: int search(vector<int>& arr, int t) { //hald of the vector is sorted and half isnt int l=0,h=arr.size()-1; while(l<=h){ int mid = l+(h-l)/2; if(arr[mid]==t) return mid; if(arr[l] <= arr[mid]){ //left sorted if(arr[l]<=t && t<=arr[mid]){ h=mid-1; }else{ l=mid+1; } } else{ //right sorted if(t>=arr[mid] && t<=arr[h]){ l=mid+1; }else{ h=mid-1; } } } return -1; } };