CodeOath
← All problems

Search in Rotated Sorted Array

Medium
arraysbinary-search

Given a rotated sorted array nums of distinct integers and a target, return the index of target if found, otherwise -1. Must run in O(log n) time.

Example:

Input: nums = [4,5,6,7,0,1,2], target = 0
Output: 4

Constraints:

  • 1 <= nums.length <= 5000
  • all values in nums are distinct