Skip to content

Commit 3fde699

Browse files
committed
Time: 0 ms (100%), Space: 45.7 MB (46.88%) - LeetHub
1 parent 64d6f9b commit 3fde699

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
public void setZeroes(int[][] matrix) {
3+
boolean zeroinFirstCol = false;
4+
for (int row = 0; row < matrix.length; row++) {
5+
if (matrix[row][0] == 0) zeroinFirstCol = true;
6+
for (int col = 1; col < matrix[0].length; col++) {
7+
if (matrix[row][col] == 0) {
8+
matrix[row][0] = 0;
9+
matrix[0][col] = 0;
10+
}
11+
}
12+
}
13+
14+
for (int row = matrix.length - 1; row >= 0; row--) {
15+
for (int col = matrix[0].length - 1; col >= 1; col--) {
16+
if (matrix[row][0] == 0 || matrix[0][col] == 0) {
17+
matrix[row][col] = 0;
18+
}
19+
}
20+
if (zeroinFirstCol) {
21+
matrix[row][0] = 0;
22+
}
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)