2
public void setZeroes(int[][] matrix) {3
if (matrix == null || matrix.length == 0 || matrix[0].length == 0) return;5
int row = matrix.length;6
int col = matrix[0].length;8
boolean firstColumnZero = false;9
boolean firstRowZero = false;11
// Check if first column should be made zero12
for (int i = 0; i < row; i++) {13
if (matrix[i][0] == 0) {14
firstColumnZero = true;19
// Check if first row should be made zero20
for (int i = 0; i < col; i++) {21
if (matrix[0][i] == 0) {27
// Traverse the matrix excluding first row and column28
// If zero is found, update the same in first row and column30
for (int i = 1; i < row; i++) {31
for (int j = 1; j < col; j++) {32
if (matrix[i][j] == 0) {39
// Now traverse again and update40
for (int i = 1; i < row; i++) {41
for (int j = 1; j < col; j++) {42
if (matrix[i][0] == 0 || matrix[0][j] == 0) {48
// Traverse and update first column49
if (firstColumnZero) {50
for (int i = 0; i < row; i++) {55
// Traverse and update first row57
for (int j = 0; j < col; j++) {