-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset-matrix-zeroes.java
More file actions
37 lines (28 loc) · 901 Bytes
/
Copy pathset-matrix-zeroes.java
File metadata and controls
37 lines (28 loc) · 901 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
30
31
32
33
34
35
36
37
class Solution {
public void setZeroes(int[][] matrix) {
int[] row = new int[matrix.length];
int[] col = new int[matrix[0].length];
for(int i=0; i<matrix.length; i++){
for(int j =0; j< matrix[i].length; j++){
if(matrix[i][j] == 0){
row[i] = 1;
col[j] = 1;
}
}
}
for(int i =0; i< row.length; i++){
if(row[i] == 1){
for(int p = 0; p< matrix[i].length; p++){
matrix[i][p] = 0;
}
}
}
for(int j =0; j< col.length; j++){
if(col[j] == 1){
for(int p = 0; p< matrix.length; p++){
matrix[p][j] = 0;
}
}
}
}
}