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.
1 parent 57a4bf2 commit 794c023Copy full SHA for 794c023
search-in-rotated-sorted-array/search-in-rotated-sorted-array.cpp
@@ -0,0 +1,31 @@
1
+class Solution {
2
+public:
3
+ int search(vector<int>& nums, int target) {
4
+ int low = 0;
5
+ int high = nums.size()-1;
6
+ while(low<=high)
7
+ {
8
+ int mid = low + (high-low)/2;
9
+ if(nums[mid]==target)
10
+ return mid;
11
+ else
12
13
+ if(nums[low]<=nums[mid])
14
15
+ if(target<nums[mid] && target>=nums[low])
16
+ high = mid-1;
17
18
+ low = mid+1;
19
+ }
20
21
22
+ if(target>nums[mid] && target<=nums[high])
23
24
25
26
27
28
29
+ return -1;
30
31
+};
0 commit comments