mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 00:25:22 +08:00
20 lines
391 B
Go
20 lines
391 B
Go
package leetcode
|
|
|
|
func searchMatrix(matrix [][]int, target int) bool {
|
|
if len(matrix) == 0 {
|
|
return false
|
|
}
|
|
m, low, high := len(matrix[0]), 0, len(matrix[0])*len(matrix)-1
|
|
for low <= high {
|
|
mid := low + (high-low)>>1
|
|
if matrix[mid/m][mid%m] == target {
|
|
return true
|
|
} else if matrix[mid/m][mid%m] > target {
|
|
high = mid - 1
|
|
} else {
|
|
low = mid + 1
|
|
}
|
|
}
|
|
return false
|
|
}
|