Search in Rotated Sorted Array II
An ascending sorted array that may contain duplicates has been rotated at an unknown pivot. Given the rotated array nums and a target, return true if target is present, otherwise false.
Open official problem prompt ↗Decide membership in a sorted-then-rotated array where duplicate values can obscure the pivot.
A deck sorted then cut at a random spot. Usually you can see which side of the cut is still in order; but when the top, middle, and bottom cards all read the same, you can only peel one card off each end and look again.
- Input
- nums = [2,5,6,0,0,1,2], target = 0
- Output
- true
- Why
- 0 appears at indices 3 and 4, so the target exists in the array.
1 <= nums.length <= 5000-10^4 <= nums[i] <= 10^4nums is guaranteed to be an ascending array rotated at some pivot-10^4 <= target <= 10^4