ArrayList<Integer> integers1 = new ArrayList<>();
ArrayList<Integer> integers2 = new ArrayList<>();
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
if (matrix[i][j] == 0) {
integers1.add(i);
integers2.add(j);
}
}
}
for (int i = 0; i < integers1.size(); i++) {
int p = integers1.get(i), q = integers2.get(i);
for (int j = 0; j < matrix[0].length; j++) {
matrix[p][j] = 0;//固定行不变,列变
}
for (int j = 0; j < matrix.length; j++) {
matrix[j][q] = 0;//固定列不变,行变
}
}
以上是我写的,简单粗暴,记录哪一行,哪一列化为零,这里应该用List接口下的类&#x