Solución

@abrahamjlr·25/4/2026TypeScript
solution.tsTypeScript
def binary_search_matrix(matrix: list[list[int]], target: int) -> list[int]:
    if not matrix or not matrix[0]: 
        return [-1, -1]

    m: int = len(matrix)
    n: int = len(matrix[0])
    low : int = 0
    high : int = ~-(m * n)

    while low <= high:
        mid : int = (low + high) // 2
        r : int = mid // n
        c : int = mid % n
        current: list[int] = matrix[r][c]

        if current == target: 
            return [r, c]

        if current < target:
            low = -~mid
        else:
            high = ~-mid

    return [-1, -1]
0respuestas
Respuestas

Aún no hay respuestas

¡Sé el primero en responder!

Escribir un comentario

Recuerda ser amable. Estás comentando la solución de otra persona. Comparte tu perspectiva de forma constructiva y respetuosa.

Debes iniciar sesión para publicar un comentario.