File tree 2 files changed +44
-0
lines changed
2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 28
28
3 . [ Mirror Reflection] ( https://leetcode.com/explore/challenge/card/november-leetcoding-challenge/566/week-3-november-15th-november-21st/3534/ ) ➡️ [ CPP Solution] ( Week3/mirrorReflection.cpp )
29
29
4 . [ Merge Intervals] ( https://leetcode.com/explore/challenge/card/november-leetcoding-challenge/566/week-3-november-15th-november-21st/3535/ ) ➡️ [ CPP Solution] ( Week3/merge.cpp )
30
30
5 . [ Decode String] ( https://leetcode.com/explore/challenge/card/november-leetcoding-challenge/566/week-3-november-15th-november-21st/3536/ ) ➡️ [ CPP Solution] ( Week3/decodeString.cpp )
31
+ 6 . [ Search in Rotated Sorted Array II] ( https://leetcode.com/explore/challenge/card/november-leetcoding-challenge/566/week-3-november-15th-november-21st/3537/ ) ➡️ [ CPP Solution] ( Week3/search.cpp )
31
32
32
33
## Week 4 🚧
33
34
Coming soon...
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ bool search (vector<int >& nums, int target) {
4
+ int n = nums.size ();
5
+ if (n == 0 ) return false ;
6
+
7
+ int low = 0 , high = n - 1 , mid, first = nums[0 ];
8
+
9
+ while (low <= high) {
10
+
11
+ while (low < high && nums[low] == nums[low + 1 ])
12
+ low++;
13
+
14
+ while (low < high && nums[high] == nums[high - 1 ])
15
+ high--;
16
+
17
+
18
+ mid = low + (high - low) / 2 ;
19
+ int value = nums[mid];
20
+
21
+ if (value == target) return true ;
22
+
23
+ bool am_big = value >= first;
24
+ bool target_big = target >= first;
25
+
26
+ if (am_big == target_big) {
27
+ if (value < target) {
28
+ low = mid + 1 ;
29
+ } else {
30
+ high = mid - 1 ;
31
+ }
32
+ } else {
33
+ if (am_big) {
34
+ low = mid + 1 ;
35
+ } else {
36
+ high = mid - 1 ;
37
+ }
38
+ }
39
+ }
40
+
41
+ return false ;
42
+ }
43
+ };
You can’t perform that action at this time.
0 commit comments