Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

int findMin(vector<int> &num) { int n=num.size(); int min1,min2; for(int i=1;i<n-1;i++) { if(num[i]<num[i-1]&&num[i]<num[i+1]) return num[i]; } return num[0]>num[n-1]?num[n-1]:num[0]; }

Well, if the vector's min element is the last one, looks like {4,5,6,7,0}, your code will have a O(n) complexity. I think you should think about using binary search.

{4,5,6,7,0}

Thanks for your advice!

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