74. 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 1:
Example 2:
解题要点:
把整个2d数组看作一条1d数组,长度可以计算为n * m - 1。然后用二分算法搜素目标数字。
Last updated
Was this helpful?