java solution


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

  • 0

    it is easy to understand ,


Log in to reply
 

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