Search a Rotated Sorted Array
Problem statement
An integer array nums has distinct values. It was sorted in strictly increasing order, then possibly rotated without changing the circular order.
Return the zero-based index of target, or -1 when it is absent. The array may also remain in its original sorted order.
Function
search(nums: int[], target: int) → intExamples
Example 1
nums = [4,5,6,7,0,1,2]target = 0return = 4The target occurs at zero-based index 4.
Example 2
nums = [4,5,6,7,0,1,2]target = 3return = -1The target does not occur in either sorted segment.
Example 3
nums = [1]target = 0return = -1The only value differs from the target.
Constraints
1 <= nums.length <= 5000.-10^4 <= nums[i], target <= 10^4.- All values are distinct;
numsis a rotation of an increasing array.