题目叙述:
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.
(1)每一行从左到右依次增大
(2)每一行的第一个数比上一行的最后一个数大
For example,
Consider the following matrix:
[
[1, 3, 5, 7],
[10, 11, 16, 20],
[23, 30, 34, 50]
]
Given target = 3, return true.
题目求解:
代码实现(c++)
class Solution {
public:
//利用vector<vector<int>>& matrix表示二维整型数组
bool searchMatrix(vector<vector<int>>& matrix, int target) {
//m为数组行数,n为数组列数
i