Why it wrong answer?


  • 0
    S
    bool searchMatrix(int* matrix, int matrixRowSize, int matrixColSize, int target) {
    if(matrix != NULL && matrixRowSize>0 && matrixColSize>0){
        int row=0;
        int column=matrixColSize-1;
        while(row<matrixRowSize && column>=0){
            if(matrix[row*matrixColSize+column] == target){
                return true;
                break;
            }
            else if(matrix[row*matrixColSize+column]>target){
                --column;
            }
            else{
                
                ++row;
            }
        }
    }
    return false;
    

    }


Log in to reply
 

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