Can u send solution to the qn, i wanna be sure

can u send solution to the qn, i wanna be sure.
my solution: can u debug it?? it is giving error on leetcode.

class Solution {
public:

bool searchMatrix(vector<vector<int>>& matrix, int target) {
    int n=matrix.size()-1, m=matrix[0].size()-1, c=m-1, r=0;
    while(matrix[r][c]!=target)
    {
        if(r>m || c>n) return false;
        if(target > matrix[r][c])
        {
            r=r+1;
        }
        else if(target < matrix[r][c])
        {
            c=c-1;
        }
        else if(target==matrix[r][c]) return true;
    }
    return true;
}

};

hi @sidharth.delhi12_20344cb0d809bedb
corrected code -->

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

hi @sidharth.delhi12_20344cb0d809bedb
is it clear now??

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.