题解 | 二维数组中的查找
二维数组中的查找
https://www.nowcoder.com/practice/abc3fe2ce8e146608e868a70efebf62e
class Solution { public: //从左到右是递增从上到下递增,右上角作为比较点利用排除法 bool Find(int target, vector<vector<int> >& array) { int row = 0; int col = array[0].size()-1; while(row < array.size() && col >= 0){ if( array[row][col] == target){ return true; }else if(array[row][col] < target){ row++; }else if(array[row][col] > target){ col--; } } return false; } };