Suppose an array of length
n1nnums = [0,1,2,4,5,6,7][4,5,6,7,0,1,2]4[0,1,2,4,5,6,7]7Notice that rotating an array
[a[0], a[1], a[2], ..., a[n-1]][a[n-1], a[0], a[1], a[2], ..., a[n-2]]Given the sorted rotated array
numsYou must write an algorithm that runs in
O(log n) timeExample 1:
Input: nums = [3,4,5,1,2]
Output: 1
Explanation: The original array was [1,2,3,4,5] rotated 3 times.Example 2:
Input: nums = [4,5,6,7,0,1,2]
Output: 0
Explanation: The original array was [0,1,2,4,5,6,7] and it was rotated 4 times.n == nums.length1 <= n <= 5000-5000 <= nums[i] <= 5000numsnums1nSolve problems, verify your skills, and earn XP.