diff --git a/src/main/java/com/cool/hot100/matrix/Num73.java b/src/main/java/com/cool/hot100/matrix/Num73.java new file mode 100644 index 0000000..8260a7e --- /dev/null +++ b/src/main/java/com/cool/hot100/matrix/Num73.java @@ -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