package 清除行列;
public class Clearer {
public int[][] clearZero(int[][] mat, int n) {
// write code here
boolean[] row = new boolean[n];
boolean[] col = new boolean[n];
for(int i = 0;i<n;i++){
for(int j = 0;j<n;j++){
if(mat[i][j] == 0){
row[i] = true;
col[j] = true;
}
}
}
for(int i=0;i<n;i++){
if(row[i]){
for(int j=0;j<n;j++){
mat[i][j] = 0;
}
}
if(col[i]){
for(int j=0;j<n;j++){
mat[j][i] = 0;;
}
}
}
return mat;
}
public static void main(String[] args) {
}
}
清除行列
最新推荐文章于 2023-09-26 19:51:56 发布