Fácil15 pts
Binary Search
Traducción al español en progresoEl contenido detallado de esta lección aún se está traduciendo. Mientras tanto, se muestra en inglés.
Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return -1. Binary search works by repeatedly dividing the search interval in half. Example: nums=[−1,0,3,5,9,12], target=9 → index 4
Entrada
Line 1: n (array size). Line 2: n space-separated sorted integers. Line 3: target.
Salida
The index of target (0-based), or -1 if not found.
Ejemplo
6 -1 0 3 5 9 12 9
Esperado
4
Loading editor…
Resultado
Sin salida aún. Ejecuta tu código para ver resultados.