0240. 搜索二维矩阵 II #198
Replies: 1 comment
-
这里提供一种取巧的方法。 class Solution {
public:
bool searchMatrix(vector<vector<int>>& matrix, int target) {
int m = matrix.size(), n = matrix[0].size();
int row = 0, col = n - 1;
while (row < m && col >= 0) {
if (matrix[row][col] == target) {
return true;
} else if (matrix[row][col] > target) {
col--;
} else {
row++;
}
}
return false;
}
}; 方法的时间复杂度为 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
0240. 搜索二维矩阵 II
https://algo.itcharge.cn/Solutions/0200-0299/search-a-2d-matrix-ii/
Beta Was this translation helpful? Give feedback.
All reactions