LeetCode 74. 搜索二维矩阵
题目描述
思路分析
思路描述
参考代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
func searchMatrix(matrix [][]int, target int) bool {
m, n := len(matrix), len(matrix[0])
left, right := 0, m*n-1
for left <= right {
mid := left + (right-left)/2
cur := matrix[mid/n][mid%n]
if cur == target {
return true
} else if cur > target {
right = mid - 1
} else {
left = mid + 1
}
}
return false
}
1
write your code here
相似题目
题目 | 难度 | 题解 |
---|---|---|
搜索二维矩阵 II | Medium |
CC BY-NC-SA 4.0
许可协议,转载请注明出处!
本博客所有文章除特别声明外,均采用