二维数组的查找
class Solution {
public:
bool Find(int target, vector<vector<int> > array) {
int row_size=array.size();
int col_size=array[0].size();
int i=0;
int j=col_size-1;
while(i<row_size&&j>=0){
if(array[i][j]==target)
return true;
if(array[i][j]>target){
j--;
continue;
}
if(array[i][j]<target){
i++;
continue;
}
}
return false;
}
};//从右上角的元素开始比较,target比它小,则向下移动,比它大,则向左移动

浙公网安备 33010602011771号