Skip to content

Commit bd7fef4

Browse files
73. Set Matrix Zeroes (java)
1 parent da301b8 commit bd7fef4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public void setZeroes(int[][] matrix) {
3+
int matrixRow = matrix.length, matrixCol = matrix[0].length;
4+
boolean[] row = new boolean[matrixRow], col = new boolean[matrixCol];
5+
for (int i = 0; i < matrixRow; i++) {
6+
for (int j = 0; j < matrixCol; j++) {
7+
if (matrix[i][j] == 0) {
8+
row[i] = true;
9+
col[j] = true;
10+
}
11+
}
12+
}
13+
for (int i = 0; i < matrixRow; i++) {
14+
if (row[i]) for (int k = 0; k < matrixCol; k++) matrix[i][k] = 0;
15+
}
16+
for (int j = 0; j < matrixCol; j++) {
17+
if (col[j]) for (int k = 0; k < matrixRow; k++) matrix[k][j] = 0;
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)