MCPcopy Create free account
hub / github.com/careercup/ctci / setZeros

Method setZeros

java/Chapter 1/Question1_7/Question.java:73–100  ·  view source on GitHub ↗
(int[][] matrix)

Source from the content-addressed store, hash-verified

71 }
72
73 public static void setZeros(int[][] matrix) {
74 boolean[] row = new boolean[matrix.length];
75 boolean[] column = new boolean[matrix[0].length];
76
77 // Store the row and column index with value 0
78 for (int i = 0; i < matrix.length; i++) {
79 for (int j = 0; j < matrix[0].length;j++) {
80 if (matrix[i][j] == 0) {
81 row[i] = true;
82 column[j] = true;
83 }
84 }
85 }
86
87 // Nullify rows
88 for (int i = 0; i < row.length; i++) {
89 if (row[i]) {
90 nullifyRow(matrix, i);
91 }
92 }
93
94 // Nullify columns
95 for (int j = 0; j < column.length; j++) {
96 if (column[j]) {
97 nullifyColumn(matrix, j);
98 }
99 }
100 }
101
102 public static boolean matricesAreEqual(int[][] m1, int[][] m2) {
103 if (m1.length != m2.length || m1[0].length != m2[0].length) {

Callers 1

mainMethod · 0.95

Calls 2

nullifyRowMethod · 0.95
nullifyColumnMethod · 0.95

Tested by

no test coverage detected