Skip to content

Commit 285e2f1

Browse files
authored
Create Sorted and Rotated Minimum (#660)
2 parents 08b82ac + 6d6b8c8 commit 285e2f1

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Sorted and Rotated Minimum

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
int findMin(vector<int>& arr) {
4+
// complete the function here
5+
int n = arr.size();
6+
if(n == 1)
7+
{
8+
return arr[0];
9+
}
10+
for(int i = 0; i < n; i++)
11+
{
12+
if(arr[(i-1+n)%n] > arr[i] && arr[i] < arr[(i+1)%n])
13+
{
14+
return arr[i];
15+
}
16+
}
17+
return -1;
18+
}
19+
};

0 commit comments

Comments
 (0)