Search in Rotated Sorted Array

There is an integer array nums sorted in ascending order with distinct values, which is possibly rotated at an unknown pivot. Given this array and an integer target, the task is to find the index of target in nums, or return -1 if it is not present. The solution must have a runtime complexity of O(log n).

Constraints

  • 1 <= nums.length <= 5000
  • -10^4 <= nums[i] <= 10^4
  • All values of nums are unique.
  • nums is an ascending array that is possibly rotated.
  • -10^4 <= target <= 10^4
Saving… · 2 lines
class Solution:
def searchInRotatedSortedArray(self, nums, target) -> int:
Console

Click Run to execute sample tests.