Question Description
In a two-dimensional array, each row is sorted in increasing order from left to right, and each column is sorted in increasing order from top to bottom. Please complete a function, input such a two-dimensional array and an integer, and determine whether the array contains the integer.
Time limit: 1 second Space limit: 32768K Heat index: 654677
Knowledge points of this topic: Find
#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
bool Find(int target, vector<vector<int> > array) {
int row=array.size();
int col=array[0].size();
int i,j;
i=row-1,j=0;
while(i>=0&&j<=col-1){
if(target==array[i][j])
return true;
if(target<array[i][j]){
i--;
continue;
}
if(target>array[i][j]){
j++;
continue;
}
}
return false;
}
};