题解 | #二维数组中的查找#
// 从右上角开始即可
class Solution {
public:
bool Find(int target, vector<vector<int> > array) {
const int R = array.size();
const int C = array[0].size();
int r = 0;
int c = C - 1;
while (r >= 0 && r < R && c >= 0 && c < C) {
if (target < array[r][c]) {
--c;
} else if (target > array[r][c]) {
++r;
} else {
return true;
}
}
return false;
}
};