标签:nbsp sea ble com false lan 查找 alt ret
来源:力扣(LeetCode)
class Solution { public: bool searchMatrix(vector<vector<int>>& matrix, int target) { if (matrix.empty()) return false; int rows = matrix.size(); int cols = matrix[0].size(); //主要思路:从右上角数开始对比,如小于右上角数则列数-1,如大于则行数-1 int cur_row = 0; int cur_col = cols - 1; while (cur_row < rows && cur_col >= 0) { if (matrix[cur_row][cur_col] == target) return true; else if (matrix[cur_row][cur_col] > target) --cur_col; else ++cur_row; } return false; } };
LeetCode 240. 搜索二维矩阵 II Search a 2D Matrix II (Medium)
标签:nbsp sea ble com false lan 查找 alt ret
原文地址:https://www.cnblogs.com/ZSY-blog/p/12916015.html