LeetCode 74. Search a 2D Matrix
Solution1:我的答案
《剑指offer》原题
class Solution {
public:
bool searchMatrix(vector<vector<int>>& matrix, int target) {
if (!matrix.size() || !matrix[0].size()) return false;
int m = matrix.size() - 1, n = matrix[0].size() - 1, i = 0, j = n;
while (i <= m && j >= 0) {
if (matrix[i][j] == target) return true;
else if (matrix[i][j] < target) i++;
else j--;
}
return false;
}
};