Dodomeki
Sign in

21. Search in Order

Easy

Given an array numeros sorted in increasing order and an integer alvo, return the index of the target. If it is not in the array, return -1.

Example 1
Input: numeros = [-5, 0, 3, 8, 12], alvo = 8
Output: 3
Example 2
Input: numeros = [-5, 0, 3, 8, 12], alvo = 4
Output: -1
Constraints
  • 0 <= numeros.length <= 10000
  • Os valores de numeros são distintos
  • -100000 <= numeros[i], alvo <= 100000
Binary searchArrays
Caso 1
numeros =
[-5,0,3,8,12]
alvo =
8
Expected =
3
Caso 2
numeros =
[-5,0,3,8,12]
alvo =
4
Expected =
-1

Run checks these 2 cases. Submit runs all 7, including hidden ones.