题解 | #矩阵置零#
矩阵置零
http://www.nowcoder.com/practice/e77f5c093978493396b22b9bc01af12d
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param matrix int整型ArrayList<ArrayList<>>
*/
public void setZeroMatrix (ArrayList<ArrayList<Integer>> matrix) {
int m = matrix.size();
int n = matrix.get(0).size();
boolean[][] dp = new boolean[m][n];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (matrix.get(i).get(j) == 0){
process1(dp, i, j);
}
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (dp[i][j] == true){
matrix.get(i).set(j, 0);
}
}
}
}
public static void process1(boolean[][] matrix, int x, int y){
for (int i = 0; i < matrix.length; i++) {
matrix[i][y] = true;
}
for (int j = 0; j < matrix[0].length; j++) {
matrix[x][j] = true;
}
}
}