public static int searchMatrix2(ArrayList<ArrayList<Integer>> matrix, int target) {
        // write your code
    	if(matrix == null || matrix.size() == 0)
    		return 0;
    	int rowL = matrix.size();
    	int colL = matrix.get(0).size();
    	int row = 0, col = colL - 1;
    	int count = 0;
    	while(row >=0 && row < rowL && col >=0 && col < colL){
    		if(matrix.get(row).get(col) == target){
    			count ++;
    			col --;
    		}else if(matrix.get(row).get(col) > target){
    			//go left
    			col --;
    		}else{
    			//matrix[row][col] < target
    			//go down
    			row++;
    		}
    	}
    	return count;
    }