JAVA---Easy version to understand.


  • 0
    H
        public boolean searchMatrix(int[][] matrix, int target) {
        if(matrix==null||matrix.length==0)
           return false;
        int rows=matrix.length,columns=matrix[0].length;
        int rowNumber=0,columnNumber=columns-1;
        while(rowNumber<rows&&columnNumber>=0){
            if(matrix[rowNumber][columnNumber]==target)
             return true;
            else if(matrix[rowNumber][columnNumber]<target)
              rowNumber++;
            else
            columnNumber--;  
        }
        return false;
    }

Log in to reply
 

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