# Simplest and fastest C++ solution O(lg N), you can't beat this!

• Binary search: basically eliminate the impossible elements by half each time by exploiting the sorted property.

``````    int findMin(vector<int> &num) {
int lo =0, hi = num.size()-1;
while(lo<hi){
int mid=(lo+hi)/2;
if(num[mid]>num[hi]) lo=mid+1;
else hi=mid;
}
return num[lo];
}``````

• This post is deleted!

• Well, i think the algorithm in my way can work better sometimes than yours. I add a `if` clause to judge whether the `mid` situation is the min element. But yours must have to do a while again.

• Hey man, lo+hi can overflow. That's why it's mentioned in "Programming Pearls" that only 10% of the programmers can get a correct binary search implementation.

• well if u want u may use `int mid = lo + (hi-lo)/2;` , if u really want to be pedantic then everyone should use `size_t hi=num.size()-1` instead of `int`.

• I think so too.

• the same as mine, very good and concise solution

• Agree with Bluefeature

• It would be incorrect if the input is [1,1,0,1].Besides,if num.empty() is true your program would crash.

• Oops,my fault.I didn't recognize the condition:"You may assume no duplicate exists in the array."

• I can't find yours, can you link to it?

• I think maybe like this;

if(mid != 0 && mid != numsSize-1 && nums[mid-1] > nums[mid] && nums[mid+1] > nums[mid]) {

low = mid; break;

}

• This post is deleted!

• might better adding early termination if no rotation at all.

``````int findMin(vector<int> &nums) {
int lo =0, hi = nums.size()-1;
while(nums[lo]>nums[hi] && lo<hi){
int mid=lo+((hi-lo)>>1);
if(nums[mid]>nums[hi]) lo=mid+1;
else hi=mid;
}
return nums[lo];
}
``````

• arrogance beat u

• @chuchao333 emmm, we always ignore this point by default.. also i don't think it is important on algorithm ....

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.