题解 | 二维数组中的查找
二维数组中的查找
https://www.nowcoder.com/practice/abc3fe2ce8e146608e868a70efebf62e
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param target int整型
* @param array int整型vector<vector<>>
* @return bool布尔型
*/
bool Find(int target, vector<vector<int> >& array) {
int row = array[0].size();
int col = array.size();
int y = row - 1;
int x = 0;
while( y >= 0 && x < col){
int tmp = array[x][y];
if(tmp > target) y--;
else if(tmp < target) x ++;
else return true;
}
return false;
}
};

查看9道真题和解析