C++ 代码
class Solution {
public:
bool searchArray(vector<vector<int>> array, int target) {
// 判断边界条件
if(array.size() == 0 || array[0].size() == 0)
return false;
int i = 0, j = array[0].size() - 1; // 从右上角开始寻找
while(i < array.size() && j >= 0)
{
if(array[i][j] == target)
return true;
else if(array[i][j] > target)
j--;
else
i++;
}
return false;
}
};