# My C++ solution 24ms is there any better solution ?

• ``````class Solution {
public:
int findMin(vector<int> &num) {
int start = 0;
int end = num.size()-1;
int mid;
while(start<end){
if(num[start]<num[end])
break;
mid = start+(end-start)/2;
if(num[mid]>num[end]){
start = mid+1;
}
else if(num[mid]==num[end]){
start++;
end--;
}
else
end= mid;
}
return num[start];
}
};``````

• 24ms, same as mine

• 9ms. Did a binary search for the equal case instead of just decrementing

https://leetcode.com/submissions/detail/99593150/

• My 6ms c++ soln

``````class Solution {
public:
int findMin(vector<int>& nums) {
int low=0;
int high=nums.size()-1;
while(low<high){
int  mid=low+(high-low)/2;
if (nums[mid]>nums[high]) low=mid+1;
else if(nums[mid]<nums[high]) high=mid;
else { //this is how you break th eequality condition. just increase or decrease the low or high to break the tie;
if (nums[mid]<nums[low]) low++;
else high--;
}
}
return nums[low];

}
};``````

• @veenaveera

``````class Solution {
public:
int findMin(vector<int>& nums) {
int ans = nums[0];
for(auto n:nums) ans = min(ans,n);
return ans;
}
};
``````

Mine is easier. No complexity difference, both in O(n). 6 ms.

• This post is deleted!

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