class Solution {
public:
int findMin(vector<int> &num) {
int n = num.size();
if( n == 1 ) {
return num[0];
}
int low = 0 , high = n-1;
while ( low<= high ) {
int mid = low + (high-low)/2;
if( mid != n-1 && num[mid] > num[mid+1] ) {
return num[mid + 1];
}
else if( mid != 0 && num[mid-1] > num[mid] ) {
return num[mid];
}
else if (num[low] < num[mid] ) {
low = mid + 1;
}
else {
high = mid - 1;
}
}
return num[0];
}
};
Arpit's Newsletter read by 15000+ engineers
🔥 Thrice a week, in your inbox, an essay about system design, distributed systems, microservices, programming languages internals, or a deep dive on some super-clever algorithm, or just a few tips on building highly scalable distributed systems.