An array sorted in non-decreasing order, possibly with repeated values, has been rotated at some unknown pivot k, so it reads [nums[k], ..., nums[n-1], nums[0], ..., nums[k-1]]. Given the rotated array nums and an integer target, return true if target appears in nums and false otherwise. Aim to do as few operations as possible.
An array sorted in non-decreasing order, possibly with repeated values, has been rotated at some unknown pivot k, so it reads [nums[k], ..., nums[n-1], nums[0], ..., nums[k-1]]. Given the rotated array nums and an integer target, return true if target appears in nums and false otherwise. Aim to do as few operations as possible.
Example 1:
Input: {"nums":[2,5,6,0,0,1,2],"target":0}
Output: true
Constraints:
1≤nums.length≤5000
−104≤nums[i]≤104
nums is guaranteed to be rotated at some pivot.
−104≤target≤104
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[2,5,6,0,0,1,2],"target":0}
Search for 0 in a rotated array of 7 values. lo and hi start at the two ends.