My Easy Java Solution


  • 0
    B
    public boolean searchMatrix(int[][] matrix, int target) {
    		int rowLen = matrix.length;
    		int columnLen = matrix[0].length;
    		int row = rowLen - 1, column = 0;
    		while (row >= 0 && column < columnLen) {
    			if (matrix[row][column] == target) {
    				return true;
    			}
    			if (matrix[row][column] > target) {
    				if (column != 0) {
    					return false;
    				}
    				row--;
    			} else {
    				column++;
    			}
    
    		}
    		return false;
    	}

Log in to reply
 

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