package main
import (
"fmt"
)
func searchMatrix(matrix [][]int, target int) bool {
rows := len(matrix)
if rows == 0 {
fmt.Println("Not found")
return false
}
cols := len(matrix[0])
row := 0
col := cols - 1
for row < rows && col >= 0 {
value := matrix[row][col]
if value == target {
fmt.Printf("Found: i = %d j = %d\n", row, col)
return true
} else if value > target {
col--
} else {
row++
}
}
fmt.Println("Not found")
return false
}
func main() {
matrix := [][]int{
{2, 3, 5, 7, 8},
{10, 13, 17, 18, 19},
{25, 26, 30, 37, 38},
{43, 46, 50, 51, 99},
}
searchMatrix(matrix, 37)
}
/*
run:
Found: i = 2 j = 3
*/