Search in 2d matrix I am getting error

Ques:-https://leetcode.com/problems/search-a-2d-matrix-ii/

Code:- bool searchMatrix(vector<vector>& matrix, int target) {
int m=matrix.size()-1;
int n=matrix[0].size()-1;
if(m<=0 && n<=0){
return false;
}
int i=0,j=n;
while(i<=m && j>=0){
if(matrix[i][j]>target){
j–;
}
else if(matrix[i][j]<target){
i++;
}
else{
return true;
}
}
return false;
}

hey @manikjindal49 please share your code using ide.codingblocks.com

Ques:-https://leetcode.com/problems/search-a-2d-matrix-ii/ Code:-https://ide.geeksforgeeks.org/zyX4mPHxVN

have edited your code here


please have a look at this code.

if this solved your doubt, please mark it as resolved.

Actually its a leet code question which i am trying to solve so can you please check it there as far as i know i am applying the perfect logic so please help me out with this

The logic you have used is right, I just edited the base case of your code. Rest Everything is same. It’s also getting accepted at leetcode.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.