Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's, and return the matrix.
You must do it in place.
class Solution {
public void setZeroes(int[][] matrix) {
List<Integer> row = new ArrayList();
List<Integer> col = new ArrayList();
int n = matrix.length;
int m = matrix[0].length;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
if(matrix[i][j] == 0) {
row.add(i);
col.add(j);
}
}
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
if(row.contains(i) || col.contains(j)) {
matrix[i][j] = 0;
}
}
}
}
}