Skip to content

Commit

Permalink
Create Sorted and Rotated Minimum (#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Dec 13, 2024
2 parents 08b82ac + 6d6b8c8 commit 285e2f1
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Sorted and Rotated Minimum
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
public:
int findMin(vector<int>& arr) {
// complete the function here
int n = arr.size();
if(n == 1)
{
return arr[0];
}
for(int i = 0; i < n; i++)
{
if(arr[(i-1+n)%n] > arr[i] && arr[i] < arr[(i+1)%n])
{
return arr[i];
}
}
return -1;
}
};

0 comments on commit 285e2f1

Please sign in to comment.