c solution o(n+m)time


  • 0
    H
    bool searchMatrix(int** matrix, int matrixRowSize, int matrixColSize, int target) {
        int i=-1;
        for(int j=0;j<matrixRowSize;j++)
        {
            if(target>=matrix[j][0])
                i++;
            else
                break;
        }
        if(i==-1)
            return false;
        for(int j=0;j<matrixColSize;j++)
        {
            if(target==matrix[i][j])
                return true;
        }
        return false;
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.