Skip to content

Commit 79f23e0

Browse files
author
ZQKC
committed
81.Search in Rotated Sorted Array II
1 parent 29d80a4 commit 79f23e0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
bool search(const vector<int>& nums, int target, int beg = -1, int end = -1) {
4+
if (beg == -1 && end == -1) {
5+
beg = 0;
6+
end = nums.size() - 1;
7+
}
8+
while (beg <= end) {
9+
int mid = (beg + end) / 2;
10+
if (target == nums[mid]) {
11+
return true;
12+
}
13+
return search(nums, target, beg, mid - 1) || search(nums, target, mid + 1, end);
14+
}
15+
return false;
16+
}
17+
};

0 commit comments

Comments
 (0)