Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix.
This matrix has the following properties:
Integers in each row are sorted from left to right.
The first integer of each row is greater than the last integer of the previous row.
Example
Consider the following matrix:
Given target = 3, return true.
Solution
容易犯的错误,While 写成了IF, M x N 写成了M + N,忘记了-1 , start , end 这里是索引。 二维转一维的公式是:mid/n and mid%n
Last updated
Was this helpful?