-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathL00073.java
23 lines (22 loc) · 863 Bytes
/
L00073.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package leetcode;
public class L00073 {
public void setZeroes(int[][] matrix) {
Boolean firstRow = false, firstCol = false;
for (int r = 0; r < matrix.length; r++)
for (int c = 0; c < matrix[0].length; c++)
if (matrix[r][c] == 0) {
if (r == 0) firstRow = true;
if (c == 0) firstCol = true;
matrix[r][0] = 0;
matrix[0][c] = 0;
}
for (int r = 1; r < matrix.length; r++)
for (int c = 1; c < matrix[0].length; c++)
if (matrix[r][0] == 0 || matrix[0][c] == 0)
matrix[r][c] = 0;
if (firstRow) matrix[0] = new int[matrix[0].length];
if (firstCol)
for (int r = 0; r < matrix.length; r++)
matrix[r][0] = 0;
}
}