class Solution {

public:

bool searchMatrix(vector<vector<int>>& matrix, int target) {

```
int k=0;
for(int x=0;x<matrix.size();x++){
if(matrix[0][0]>target){
return false;
}
else if(matrix[x][0]==target)
return true;
else if((x==matrix.size()-1)||(matrix[x][0]<target&&(matrix[x+1][0]>target))){
k=x;
break;}
}
for(int low=0,high=matrix[0].size()-1,mid=0;low<=high;mid=(low+high)/2){
if(matrix[k][mid]==target)
return true;
else
if(matrix[k][mid]<target){
low=mid+1;}
if(matrix[k][mid]>target){
high=mid-1;}
}
return false;
}
```

};