We’re preparing your current view and syncing the latest data.
Given a rotated sorted array nums of unique integers and a target value, return the index of the target if it is found in the array. Otherwise, return -1. The array is originally sorted in ascending order and then rotated at an unknown pivot. Your solution must run in O(log n) time.
An integer array nums which is a rotated sorted array, and an integer target.
Return the index of the target if found, otherwise return -1.
1 <= nums.length <= 5000, -10^4 <= nums[i], target <= 10^4, All values of nums are unique.
Example 1
Input
nums = [4,5,6,7,0,1,2], target = 0
Output
4
Explanation
The target 0 is found at index 4.
Example 2
Input
nums = [4,5,6,7,0,1,2], target = 3
Output
-1
Explanation
The target 3 is not present in the array.