You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/**the first iteration (first nested for loop) is to check from top row to bottom row:
145
+
* keep the first column state into variable col0;
146
+
* then starting from the second column, check all the rest of the columns and mark its top cell and its most-left cell if it
147
+
* s a zero.*/
148
+
for (inti = 0; i < m; i++) {
149
+
if (matrix[i][0] == 0) {
150
+
col0 = 0;
151
+
}
152
+
153
+
for (intj = 1; j < n; j++) {
154
+
if (matrix[i][j] == 0) {
155
+
matrix[i][0] = 0;
156
+
matrix[0][j] = 0;
157
+
}
158
+
}
159
+
}
160
+
161
+
/**the second iteration (second nested for loop) is to check from bottom row to the top row
162
+
* from the right-most column to the second left-most column: as long as its left-most column cell or its top row cell is zero, then set that cell to be zero
163
+
* at last, check col0 variable, if it's zero, mark that row cell as zero*/
0 commit comments