File tree 2 files changed +45
-1
lines changed
2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change 29
29
| 2| [ Single Element in a Sorted Array] ( https://leetcode.com/problems/single-element-in-a-sorted-array/ ) | [ Solution] ( single_element_in_sorted_array.cpp ) |
30
30
| 3| [ Search in Rotated Sorted Array] ( https://leetcode.com/problems/search-in-rotated-sorted-array/ ) | Pending|
31
31
| 4| [ Search in Rotated Sorted Array II] ( https://leetcode.com/problems/search-in-rotated-sorted-array-ii/ ) | Pending|
32
- | 5| [ Find Minimum in Rotated Sorted Array] ( https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/ ) | Pending |
32
+ | 5| [ Find Minimum in Rotated Sorted Array] ( https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/ ) | [ Solution ] ( min_in_rotated_arr.cpp ) |
33
33
| 6| [ Find Peak Element] ( https://leetcode.com/problems/find-peak-element/ ) | [ Solution] ( peak_ele.cpp ) |
34
34
| 7| [ Find Right Interval] ( https://leetcode.com/problems/find-right-interval/ ) | Pending|
35
35
| 8| [ Reach a Number] ( https://leetcode.com/problems/reach-a-number/ ) | Pending|
Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ using namespace std ;
3
+
4
+ int findMin (vector<int > &num)
5
+ {
6
+ if (num.empty ())
7
+ return 0 ;
8
+ int low = 0 ;
9
+ int high = num.size () - 1 ;
10
+ int mid;
11
+
12
+ while (low < high)
13
+ {
14
+ mid = (low + high) / 2 ;
15
+ if (num[low] > num[mid])
16
+ {
17
+ low++;
18
+ high = mid;
19
+ }
20
+ else if (num[mid] > num[high])
21
+ {
22
+ low = ++mid;
23
+ }
24
+ else
25
+ high = mid;
26
+ }
27
+
28
+ return num[low];
29
+ }
30
+
31
+ int main ()
32
+ {
33
+ int n, target;
34
+ cin >> n;
35
+ vector<int > v;
36
+ for (int i = 0 ; i < n; i++)
37
+ {
38
+ int temp;
39
+ cin >> temp;
40
+ v.push_back (temp);
41
+ }
42
+ cout << findMin (v) << endl;
43
+ return 0 ;
44
+ }
You can’t perform that action at this time.
0 commit comments