2024/9/06 LeetCode Hot100 matrix

This commit is contained in:
Cool 2024-09-07 01:09:42 +08:00
parent 0ce86e6903
commit c0981ea681
1 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,41 @@
package com.cool.hot100.matrix;
import java.util.Arrays;
/**
* Created with IntelliJ IDEA.
*
* @Author: Cool
* @Date: 2024/09/07/0:22
* DayNumber 2
* Hard 2
* Level 3
*/
public class Num73 {
public void setZeroes(int[][] matrix) {
boolean[] row = new boolean[matrix.length];
boolean[] column = new boolean[matrix[0].length];
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[0].length; j++) {
if (matrix[i][j] == 0) {
row[i] = true;
column[j] = true;
}
}
}
for (int i = 0; i < row.length; i++) {
if (row[i]) {
Arrays.fill(matrix[i], 0);
}
}
for (int i = 0; i < column.length; i++) {
if (column[i]) {
for(int j=0;j<matrix.length;j++){
matrix[j][i]=0;
}
}
}
}
}