@Test public void shouldNotRewritePositionsWithNonZeroElements() { int[][] matrix = { { 1, 1 }, { 1, 1 } }; rewriteMatrix.rewrite(matrix); int[][] expectedMatrix = { { 1, 1 }, { 1, 1 } }; assertArrayEquals(expectedMatrix, matrix); }
public void rewrite(int[][] matrix) { validateInput(matrix); Set<Integer> rowsToSkip = new HashSet<Integer>(); Set<Integer> columnsToSkip = new HashSet<Integer>(); for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[i].length; j++) { if (shouldPaintRowAndColumn(matrix, i, j, rowsToSkip, columnsToSkip)) { rewriteRow(matrix, i, rowsToSkip); rewriteColumn(matrix, j, columnsToSkip); } } } }
RewriteRowAndColumnsWithZeros { public void rewrite(int[][] matrix) { validateInput(matrix); Set<Integer> rowsToSkip = new HashSet<Integer>(); Set<Integer> columnsToSkip = new HashSet<Integer>(); for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[i].length; j++) { if (shouldPaintRowAndColumn(matrix, i, j, rowsToSkip, columnsToSkip)) { rewriteRow(matrix, i, rowsToSkip); rewriteColumn(matrix, j, columnsToSkip); } } } } }
RewriteRowAndColumnsWithZeros { public void rewrite(int[][] matrix) { validateInput(matrix); Set<Integer> rowsToSkip = new HashSet<Integer>(); Set<Integer> columnsToSkip = new HashSet<Integer>(); for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[i].length; j++) { if (shouldPaintRowAndColumn(matrix, i, j, rowsToSkip, columnsToSkip)) { rewriteRow(matrix, i, rowsToSkip); rewriteColumn(matrix, j, columnsToSkip); } } } }  }
RewriteRowAndColumnsWithZeros { public void rewrite(int[][] matrix) { validateInput(matrix); Set<Integer> rowsToSkip = new HashSet<Integer>(); Set<Integer> columnsToSkip = new HashSet<Integer>(); for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[i].length; j++) { if (shouldPaintRowAndColumn(matrix, i, j, rowsToSkip, columnsToSkip)) { rewriteRow(matrix, i, rowsToSkip); rewriteColumn(matrix, j, columnsToSkip); } } } }  void rewrite(int[][] matrix); }
RewriteRowAndColumnsWithZeros { public void rewrite(int[][] matrix) { validateInput(matrix); Set<Integer> rowsToSkip = new HashSet<Integer>(); Set<Integer> columnsToSkip = new HashSet<Integer>(); for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[i].length; j++) { if (shouldPaintRowAndColumn(matrix, i, j, rowsToSkip, columnsToSkip)) { rewriteRow(matrix, i, rowsToSkip); rewriteColumn(matrix, j, columnsToSkip); } } } }  void rewrite(int[][] matrix);  }