-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZeroMatrix.java
More file actions
29 lines (28 loc) · 861 Bytes
/
ZeroMatrix.java
File metadata and controls
29 lines (28 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package leetcode.array;
/**
* @ClassName ZeroMatrix
* @Description 零矩阵 https://leetcode-cn.com/problems/zero-matrix-lcci/
* @Author changxuan
* @Date 2020/9/10 下午8:23
**/
public class ZeroMatrix {
/**
* 零矩阵
* @param matrix 矩阵
*/
public void setZeroes(int[][] matrix) {
boolean[] row = new boolean[matrix.length];
boolean[] column = new boolean[matrix[0].length];
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[0].length; j++) {
if (matrix[i][j] == 0){
row[i] = true;
column[j] = true;
}
}
}
for (int i = 0; i < matrix.length; i++)
for (int j = 0; j < matrix[0].length; j++)
if (row[i] || column[j]) matrix[i][j] = 0;
}
}