My 6 lines C Solution in O(n) using Staircase Search


  • 0
    R
    bool searchMatrix(int** matrix, int matrixRowSize, int matrixColSize, int target) {
        int r = 0, c = matrixColSize - 1;
        while(r<matrixRowSize && c>=0) {
            if(matrix[r][c] < target) r++;
            else if (matrix[r][c] > target) c--;
            else return true;
        }
        return false;
    }
    

Log in to reply
 

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