You get an array of numbers nums, sorted in ascending order, and a number target. Return the index of target in nums. If target is not in nums, return -1.
- All values in
numsare distinct. numscan be empty, and it can hold negative numbers.numscan hold up to 1,000,000 numbers, and the function is called many times. So your solution must run in O(log n) time.
Input: nums = [2, 5, 8, 12, 16, 23, 38, 56, 72, 91], target = 23
Output: 5
Input: nums = [-4, 0, 7, 11], target = 3
Output: -13 would sit between 0 and 7, but it is not in the array.