# Search in Rotated Sorted Array II

Follow up for "Search in Rotated Sorted Array":
What if duplicates are allowed?

Would this affect the run-time complexity? How and why?

Write a function to determine if a given target is in the array.

```public class Solution {
public boolean search(int[] nums, int target) {
int start = 0;
int end = nums.length-1;
return search(nums, target, start, end);
}

private boolean search(int[] nums, int target, int start, int end) {
if (start>end) {
return false;
}
int mid = (start+end)/2;
if (target == nums[mid]) {
return true;
}
if (nums[mid] == nums[end]) {
return search(nums, target, start, mid-1) || search(nums, target, mid+1, end);
} else if (nums[mid] > nums[end]) {
if (target<nums[mid] && target>=nums[start]) {
return search(nums, target, start, mid-1);
} else {
return search(nums, target, mid+1, end);
}
} else {
if (target>nums[mid] && target<=nums[end]) {
return search(nums, target, mid+1, end);
} else {
return search(nums, target, start, mid-1);
}
}
}
}```

Search in Rotated Sorted Array II

• 0

开心

• 0

板砖

• 0

感动

• 0

有用

• 0

疑问

• 0

难过

• 0

无聊

• 0

震惊

Question: Follow up for "Search in Rotated Sorted Array": What if duplicates are allowed? Wou
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6
Question: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6
Search in Rotated Sorted Array Implementation public class Solution { public int search(int[]
【题目】 Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0
Search in Rotated Sorted Array 题目： Suppose a sorted array is rotated at some pivot unknown
【题目】 Follow up for "Find Minimum in Rotated Sorted Array": What if duplicates are allowed