Given a rotated sorted array of integers that may contain duplicates and a target value, return true if the target exists in the array, otherwise return false. The array was originally sorted in non-decreasing order and then rotated at an unknown pivot. Due to duplicates, the search process may require checking both halves in some cases.
Example 1
Input: nums = [2,5,6,0,0,1,2], target = 0
Output: true
Explanation: The target value 0 exists in the rotated array.
Example 2
Input: nums = [2,5,6,0,0,1,2], target = 3
Output: false
Explanation: The target value 3 does not exist in the array.
Example 3
Input: nums = [1,1,1,1,1], target = 1
Output: true
Explanation: All elements are the same and equal to the target, so it exists in the array.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
2 5 6 0 0 1 2 0
true
2 5 6 0 0 1 2 3
false