1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| class Solution { public: bool searchMatrix(vector<vector<int>>& matrix, int target) { int n = matrix.size(); int r = 0, c = m - 1; while (r < n && c >= 0) { if (matrix[r][c] > target) c--; else if (matrix[r][c] < target) r++; else return true; } return false; } };
|