We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 5b06a37 + 3c48033 commit b08f10dCopy full SHA for b08f10d
binarysearch-problems/33.leetcode_search_in_rotated_array.cpp
@@ -0,0 +1,27 @@
1
+class Solution {
2
+public:
3
+ int search(vector<int>& A, int target) {
4
+ int start = 0;
5
+ int end = A.size() - 1;
6
+ while (start <end) {
7
+ int mid = start+(end-start) / 2;
8
+ if (A[mid] == target)
9
+ return mid;
10
+
11
+ if (A[start] <= A[mid]) {
12
+ if (target >= A[start] && target < A[mid]) {
13
+ end= mid - 1;
14
+ } else {
15
+ start = mid + 1;
16
+ }
17
18
+ if (target > A[mid] && target <= A[end]) {
19
20
21
22
23
24
25
+ return A[start] == target ? start : -1;
26
27
+};
0 commit comments