Loading... 这道题目只保证了矩阵从左到右、从上到下分别是单调递增,没有保证全局,所以没办法将下标映射成一维数组来做,但是矩阵的右上角和左下角保证了往不同的两个方向移动分别是减少和增加,所以可以从这两个地方开始搜索,达到类似二分的效果。 ```go func searchMatrix(matrix [][]int, target int) bool { n := len(matrix) m := len(matrix[0]) row, col := 0, m-1 for row < n && col >= 0 { if matrix[row][col] < target { row++ } else if matrix[row][col] == target { return true } else { col-- } } return false } ``` Last modification:July 9, 2025 © Allow specification reprint Support Appreciate the author AliPayWeChat Like 如果觉得我的文章对你有用,请随意赞赏