From 2922f0619f280b23209dafe18abc49015d206b3a Mon Sep 17 00:00:00 2001 From: anujgaud <146576725+anujgaud@users.noreply.github.com> Date: Sat, 16 Mar 2024 23:21:47 +0530 Subject: [PATCH 1/9] Create SetMatrixToZero.java --- .../matrixToZero/SetMatrixToZero.java | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixToZero/SetMatrixToZero.java diff --git a/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixToZero/SetMatrixToZero.java b/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixToZero/SetMatrixToZero.java new file mode 100644 index 0000000000..d195698299 --- /dev/null +++ b/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixToZero/SetMatrixToZero.java @@ -0,0 +1,115 @@ +package com.baeldung.matrixToZero; + +import java.util.*; + +public class SetMatrixToZero{ + static void setZeroesBruteForce(int[][] matrix) { + int row = matrix.length; + int col = matrix[0].length; + int [][] result = new int[row][col]; + + for(int i = 0; i rowSet = new HashSet<>(); + Set colSet = new HashSet<>(); + + for(int i = 0; i < rows; i++){ + for(int j = 0; j < cols; j++){ + if (matrix[i][j] == 0){ + rowSet.add(i); + colSet.add(j); + } + } + } + for(int row: rowSet){ + for(int j = 0; j < cols; j++){ + matrix[row][j] = 0; + } + } + for(int col: colSet) { + for(int i = 0; i < rows; i++){ + matrix[i][col] = 0; + } + } + } + static void setZeroesOptimized(int[][] matrix){ + int rows = matrix.length; + int cols = matrix[0].length; + + boolean firstRowZero = false; + boolean firstColZero = false; + + for(int j = 0; j < cols; j++){ + if (matrix[0][j] == 0) { + firstRowZero = true; + break; + } + } + + for(int i = 0; i < rows; i++){ + if (matrix[i][0] == 0) { + firstColZero = true; + break; + } + } + for(int i = 1; i < rows; i++){ + for(int j = 1; j < cols; j++){ + if (matrix[i][j] == 0){ + matrix[i][0] = 0; + matrix[0][j] = 0; + } + } + } + for(int i = 1; i < rows; i++){ + if(matrix[i][0] == 0){ + for(int j = 1; j < cols; j++){ + matrix[i][j] = 0; + } + } + } + for(int j = 1; j < cols; j++){ + if(matrix[0][j] == 0) { + for(int i = 1; i < rows; i++){ + matrix[i][j] = 0; + } + } + } + if(firstRowZero){ + for(int j = 0; j < cols; j++){ + matrix[0][j] = 0; + } + } + if(firstColZero){ + for(int i = 0; i < rows; i++){ + matrix[i][0] = 0; + } + } + } +} From f88022796a6dd2ec5fb475c049b09e35ab22a883 Mon Sep 17 00:00:00 2001 From: anujgaud <146576725+anujgaud@users.noreply.github.com> Date: Sat, 16 Mar 2024 23:32:11 +0530 Subject: [PATCH 2/9] Create SetMatrixToZeroUnitTest.java --- .../matrixtozero/SetMatrixToZeroUnitTest.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 core-java-modules/core-java-arrays-operations-advanced-2/src/test/java/com/baeldung/matrixtozero/SetMatrixToZeroUnitTest.java diff --git a/core-java-modules/core-java-arrays-operations-advanced-2/src/test/java/com/baeldung/matrixtozero/SetMatrixToZeroUnitTest.java b/core-java-modules/core-java-arrays-operations-advanced-2/src/test/java/com/baeldung/matrixtozero/SetMatrixToZeroUnitTest.java new file mode 100644 index 0000000000..e144c90ba7 --- /dev/null +++ b/core-java-modules/core-java-arrays-operations-advanced-2/src/test/java/com/baeldung/matrixtozero/SetMatrixToZeroUnitTest.java @@ -0,0 +1,53 @@ +package com.baeldung.matrixtozero; + +import org.junit.Test; + +public class SetMatrixToZeroUnitTest{ + @Test + void givenMatrix_whenUsingBruteForce_thenSetZeroes() { + int[][] matrix = { + {1, 2, 3}, + {4, 0, 6}, + {7, 8, 9} + }; + int[][] expected = { + {1, 0, 3}, + {0, 0, 0}, + {7, 0, 9} + }; + SetMatrixToZero.setZeroesBruteForce(matrix); + assertArrayEquals(expected, matrix); + } + + @Test + void givenMatrix_whenUsingExtraSpace_thenSetZeroes() { + int[][] matrix = { + {1, 2, 3}, + {4, 0, 6}, + {7, 8, 9} + }; + int[][] expected = { + {1, 0, 3}, + {0, 0, 0}, + {7, 0, 9} + }; + SetMatrixToZero.setZeroesExtraSpace(matrix); + assertArrayEquals(expected, matrix); + } + + @Test + void givenMatrix_whenUsingOptimized_thenSetZeroes() { + int[][] matrix = { + {1, 2, 3}, + {4, 0, 6}, + {7, 8, 9} + }; + int[][] expected = { + {1, 0, 3}, + {0, 0, 0}, + {7, 0, 9} + }; + SetMatrixToZero.setZeroesOptimized(matrix); + assertArrayEquals(expected, matrix); + } +} From 44aab189871e0f5a113d8c7e4d8ab94e95e34e3f Mon Sep 17 00:00:00 2001 From: anujgaud <146576725+anujgaud@users.noreply.github.com> Date: Sat, 16 Mar 2024 23:34:03 +0530 Subject: [PATCH 3/9] Delete core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixToZero directory --- .../matrixToZero/SetMatrixToZero.java | 115 ------------------ 1 file changed, 115 deletions(-) delete mode 100644 core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixToZero/SetMatrixToZero.java diff --git a/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixToZero/SetMatrixToZero.java b/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixToZero/SetMatrixToZero.java deleted file mode 100644 index d195698299..0000000000 --- a/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixToZero/SetMatrixToZero.java +++ /dev/null @@ -1,115 +0,0 @@ -package com.baeldung.matrixToZero; - -import java.util.*; - -public class SetMatrixToZero{ - static void setZeroesBruteForce(int[][] matrix) { - int row = matrix.length; - int col = matrix[0].length; - int [][] result = new int[row][col]; - - for(int i = 0; i rowSet = new HashSet<>(); - Set colSet = new HashSet<>(); - - for(int i = 0; i < rows; i++){ - for(int j = 0; j < cols; j++){ - if (matrix[i][j] == 0){ - rowSet.add(i); - colSet.add(j); - } - } - } - for(int row: rowSet){ - for(int j = 0; j < cols; j++){ - matrix[row][j] = 0; - } - } - for(int col: colSet) { - for(int i = 0; i < rows; i++){ - matrix[i][col] = 0; - } - } - } - static void setZeroesOptimized(int[][] matrix){ - int rows = matrix.length; - int cols = matrix[0].length; - - boolean firstRowZero = false; - boolean firstColZero = false; - - for(int j = 0; j < cols; j++){ - if (matrix[0][j] == 0) { - firstRowZero = true; - break; - } - } - - for(int i = 0; i < rows; i++){ - if (matrix[i][0] == 0) { - firstColZero = true; - break; - } - } - for(int i = 1; i < rows; i++){ - for(int j = 1; j < cols; j++){ - if (matrix[i][j] == 0){ - matrix[i][0] = 0; - matrix[0][j] = 0; - } - } - } - for(int i = 1; i < rows; i++){ - if(matrix[i][0] == 0){ - for(int j = 1; j < cols; j++){ - matrix[i][j] = 0; - } - } - } - for(int j = 1; j < cols; j++){ - if(matrix[0][j] == 0) { - for(int i = 1; i < rows; i++){ - matrix[i][j] = 0; - } - } - } - if(firstRowZero){ - for(int j = 0; j < cols; j++){ - matrix[0][j] = 0; - } - } - if(firstColZero){ - for(int i = 0; i < rows; i++){ - matrix[i][0] = 0; - } - } - } -} From 576925e862aa776462ac113958bfced34aa9bcd5 Mon Sep 17 00:00:00 2001 From: anujgaud <146576725+anujgaud@users.noreply.github.com> Date: Sat, 16 Mar 2024 23:36:32 +0530 Subject: [PATCH 4/9] Create SetMatrixToZero.java --- .../matrixtozero/SetMatrixToZero.java | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixtozero/SetMatrixToZero.java diff --git a/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixtozero/SetMatrixToZero.java b/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixtozero/SetMatrixToZero.java new file mode 100644 index 0000000000..46d24b0d38 --- /dev/null +++ b/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixtozero/SetMatrixToZero.java @@ -0,0 +1,115 @@ +package com.baeldung.matrixtozero; + +import java.util.*; + +public class SetMatrixToZero{ + static void setZeroesBruteForce(int[][] matrix) { + int row = matrix.length; + int col = matrix[0].length; + int [][] result = new int[row][col]; + + for(int i = 0; i rowSet = new HashSet<>(); + Set colSet = new HashSet<>(); + + for(int i = 0; i < rows; i++){ + for(int j = 0; j < cols; j++){ + if (matrix[i][j] == 0){ + rowSet.add(i); + colSet.add(j); + } + } + } + for(int row: rowSet){ + for(int j = 0; j < cols; j++){ + matrix[row][j] = 0; + } + } + for(int col: colSet) { + for(int i = 0; i < rows; i++){ + matrix[i][col] = 0; + } + } + } + static void setZeroesOptimized(int[][] matrix){ + int rows = matrix.length; + int cols = matrix[0].length; + + boolean firstRowZero = false; + boolean firstColZero = false; + + for(int j = 0; j < cols; j++){ + if (matrix[0][j] == 0) { + firstRowZero = true; + break; + } + } + + for(int i = 0; i < rows; i++){ + if (matrix[i][0] == 0) { + firstColZero = true; + break; + } + } + for(int i = 1; i < rows; i++){ + for(int j = 1; j < cols; j++){ + if (matrix[i][j] == 0){ + matrix[i][0] = 0; + matrix[0][j] = 0; + } + } + } + for(int i = 1; i < rows; i++){ + if(matrix[i][0] == 0){ + for(int j = 1; j < cols; j++){ + matrix[i][j] = 0; + } + } + } + for(int j = 1; j < cols; j++){ + if(matrix[0][j] == 0) { + for(int i = 1; i < rows; i++){ + matrix[i][j] = 0; + } + } + } + if(firstRowZero){ + for(int j = 0; j < cols; j++){ + matrix[0][j] = 0; + } + } + if(firstColZero){ + for(int i = 0; i < rows; i++){ + matrix[i][0] = 0; + } + } + } +} From 9d0024b92645418d41607284cb4c9293f8c07f0f Mon Sep 17 00:00:00 2001 From: anujgaud <146576725+anujgaud@users.noreply.github.com> Date: Sat, 16 Mar 2024 23:49:41 +0530 Subject: [PATCH 5/9] Apply formatting --- .../java/com/baeldung/matrixtozero/SetMatrixToZero.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixtozero/SetMatrixToZero.java b/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixtozero/SetMatrixToZero.java index 46d24b0d38..6362f3672c 100644 --- a/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixtozero/SetMatrixToZero.java +++ b/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixtozero/SetMatrixToZero.java @@ -33,6 +33,7 @@ public class SetMatrixToZero{ } } } + static void setZeroesExtraSpace(int[][] matrix) { int rows = matrix.length; int cols = matrix[0].length; @@ -48,17 +49,20 @@ public class SetMatrixToZero{ } } } + for(int row: rowSet){ for(int j = 0; j < cols; j++){ matrix[row][j] = 0; } } + for(int col: colSet) { for(int i = 0; i < rows; i++){ matrix[i][col] = 0; } } } + static void setZeroesOptimized(int[][] matrix){ int rows = matrix.length; int cols = matrix[0].length; @@ -79,6 +83,7 @@ public class SetMatrixToZero{ break; } } + for(int i = 1; i < rows; i++){ for(int j = 1; j < cols; j++){ if (matrix[i][j] == 0){ @@ -87,6 +92,7 @@ public class SetMatrixToZero{ } } } + for(int i = 1; i < rows; i++){ if(matrix[i][0] == 0){ for(int j = 1; j < cols; j++){ @@ -94,6 +100,7 @@ public class SetMatrixToZero{ } } } + for(int j = 1; j < cols; j++){ if(matrix[0][j] == 0) { for(int i = 1; i < rows; i++){ @@ -101,11 +108,13 @@ public class SetMatrixToZero{ } } } + if(firstRowZero){ for(int j = 0; j < cols; j++){ matrix[0][j] = 0; } } + if(firstColZero){ for(int i = 0; i < rows; i++){ matrix[i][0] = 0; From cd5a95f764b70f58a2a2f36a65aa34d4ff79ce77 Mon Sep 17 00:00:00 2001 From: anujgaud <146576725+anujgaud@users.noreply.github.com> Date: Sun, 17 Mar 2024 01:10:47 +0530 Subject: [PATCH 6/9] Included import statements in Test file --- .../com/baeldung/matrixtozero/SetMatrixToZeroUnitTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core-java-modules/core-java-arrays-operations-advanced-2/src/test/java/com/baeldung/matrixtozero/SetMatrixToZeroUnitTest.java b/core-java-modules/core-java-arrays-operations-advanced-2/src/test/java/com/baeldung/matrixtozero/SetMatrixToZeroUnitTest.java index e144c90ba7..ba8d53a11f 100644 --- a/core-java-modules/core-java-arrays-operations-advanced-2/src/test/java/com/baeldung/matrixtozero/SetMatrixToZeroUnitTest.java +++ b/core-java-modules/core-java-arrays-operations-advanced-2/src/test/java/com/baeldung/matrixtozero/SetMatrixToZeroUnitTest.java @@ -1,6 +1,7 @@ package com.baeldung.matrixtozero; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import org.junit.jupiter.api.Test; public class SetMatrixToZeroUnitTest{ @Test From e73a578dbdc343997f189dae3bab267a939ef104 Mon Sep 17 00:00:00 2001 From: anujgaud <146576725+anujgaud@users.noreply.github.com> Date: Tue, 2 Apr 2024 22:14:45 +0530 Subject: [PATCH 7/9] Update method names --- .../java/com/baeldung/matrixtozero/SetMatrixToZero.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixtozero/SetMatrixToZero.java b/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixtozero/SetMatrixToZero.java index 6362f3672c..778a5d6ce5 100644 --- a/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixtozero/SetMatrixToZero.java +++ b/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixtozero/SetMatrixToZero.java @@ -3,7 +3,7 @@ package com.baeldung.matrixtozero; import java.util.*; public class SetMatrixToZero{ - static void setZeroesBruteForce(int[][] matrix) { + static void setZeroesByNaiveApproach(int[][] matrix) { int row = matrix.length; int col = matrix[0].length; int [][] result = new int[row][col]; @@ -34,7 +34,7 @@ public class SetMatrixToZero{ } } - static void setZeroesExtraSpace(int[][] matrix) { + static void setZeroesByTimeOptimizedApproach(int[][] matrix) { int rows = matrix.length; int cols = matrix[0].length; @@ -63,7 +63,7 @@ public class SetMatrixToZero{ } } - static void setZeroesOptimized(int[][] matrix){ + static void setZeroesByOptimalApproach(int[][] matrix){ int rows = matrix.length; int cols = matrix[0].length; From dbd9448e99db9b1e3440c6f579e3e53333bde4f0 Mon Sep 17 00:00:00 2001 From: anujgaud <146576725+anujgaud@users.noreply.github.com> Date: Tue, 2 Apr 2024 22:14:57 +0530 Subject: [PATCH 8/9] Update method names --- .../matrixtozero/SetMatrixToZeroUnitTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core-java-modules/core-java-arrays-operations-advanced-2/src/test/java/com/baeldung/matrixtozero/SetMatrixToZeroUnitTest.java b/core-java-modules/core-java-arrays-operations-advanced-2/src/test/java/com/baeldung/matrixtozero/SetMatrixToZeroUnitTest.java index ba8d53a11f..ee4996457e 100644 --- a/core-java-modules/core-java-arrays-operations-advanced-2/src/test/java/com/baeldung/matrixtozero/SetMatrixToZeroUnitTest.java +++ b/core-java-modules/core-java-arrays-operations-advanced-2/src/test/java/com/baeldung/matrixtozero/SetMatrixToZeroUnitTest.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test; public class SetMatrixToZeroUnitTest{ @Test - void givenMatrix_whenUsingBruteForce_thenSetZeroes() { + void givenMatrix_whenUsingSetZeroesByNaiveApproach_thenSetZeroes() { int[][] matrix = { {1, 2, 3}, {4, 0, 6}, @@ -16,12 +16,12 @@ public class SetMatrixToZeroUnitTest{ {0, 0, 0}, {7, 0, 9} }; - SetMatrixToZero.setZeroesBruteForce(matrix); + SetMatrixToZero.setZeroesByNaiveApproach(matrix); assertArrayEquals(expected, matrix); } @Test - void givenMatrix_whenUsingExtraSpace_thenSetZeroes() { + void givenMatrix_whenUsingSetZeroesByTimeOptimizedApproach_thenSetZeroes() { int[][] matrix = { {1, 2, 3}, {4, 0, 6}, @@ -32,12 +32,12 @@ public class SetMatrixToZeroUnitTest{ {0, 0, 0}, {7, 0, 9} }; - SetMatrixToZero.setZeroesExtraSpace(matrix); + SetMatrixToZero.setZeroesByTimeOptimizedApproach(matrix); assertArrayEquals(expected, matrix); } @Test - void givenMatrix_whenUsingOptimized_thenSetZeroes() { + void givenMatrix_whenUsingSetZeroesByOptimalApproach_thenSetZeroes() { int[][] matrix = { {1, 2, 3}, {4, 0, 6}, @@ -48,7 +48,7 @@ public class SetMatrixToZeroUnitTest{ {0, 0, 0}, {7, 0, 9} }; - SetMatrixToZero.setZeroesOptimized(matrix); + SetMatrixToZero.setZeroesByOptimalApproach(matrix); assertArrayEquals(expected, matrix); } } From 306d2da98c9f66ab25fe2d1efb942cfbe74692b9 Mon Sep 17 00:00:00 2001 From: anujgaud <146576725+anujgaud@users.noreply.github.com> Date: Tue, 9 Apr 2024 23:18:22 +0530 Subject: [PATCH 9/9] Update SetMatrixToZero.java --- .../matrixtozero/SetMatrixToZero.java | 107 +++++++++++------- 1 file changed, 65 insertions(+), 42 deletions(-) diff --git a/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixtozero/SetMatrixToZero.java b/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixtozero/SetMatrixToZero.java index 778a5d6ce5..57c558caa7 100644 --- a/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixtozero/SetMatrixToZero.java +++ b/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/matrixtozero/SetMatrixToZero.java @@ -61,64 +61,87 @@ public class SetMatrixToZero{ matrix[i][col] = 0; } } - } - - static void setZeroesByOptimalApproach(int[][] matrix){ - int rows = matrix.length; - int cols = matrix[0].length; + } - boolean firstRowZero = false; - boolean firstColZero = false; - - for(int j = 0; j < cols; j++){ + static boolean hasZeroInFirstRow(int[][] matrix, int cols) { + for (int j = 0; j < cols; j++) { if (matrix[0][j] == 0) { - firstRowZero = true; - break; + return true; } } + return false; + } - for(int i = 0; i < rows; i++){ + static boolean hasZeroInFirstCol(int[][] matrix, int rows) { + for (int i = 0; i < rows; i++) { if (matrix[i][0] == 0) { - firstColZero = true; - break; + return true; } } - - for(int i = 1; i < rows; i++){ - for(int j = 1; j < cols; j++){ - if (matrix[i][j] == 0){ + return false; + } + + static void markZeroesInMatrix(int[][] matrix, int rows, int cols) { + for (int i = 1; i < rows; i++) { + for (int j = 1; j < cols; j++) { + if (matrix[i][j] == 0) { matrix[i][0] = 0; matrix[0][j] = 0; } } } - - for(int i = 1; i < rows; i++){ - if(matrix[i][0] == 0){ - for(int j = 1; j < cols; j++){ + } + + static void setZeroesInRows(int[][] matrix, int rows, int cols) { + for (int i = 1; i < rows; i++) { + if (matrix[i][0] == 0) { + for (int j = 1; j < cols; j++) { matrix[i][j] = 0; } } } - - for(int j = 1; j < cols; j++){ - if(matrix[0][j] == 0) { - for(int i = 1; i < rows; i++){ - matrix[i][j] = 0; - } - } - } - - if(firstRowZero){ - for(int j = 0; j < cols; j++){ - matrix[0][j] = 0; - } - } - - if(firstColZero){ - for(int i = 0; i < rows; i++){ - matrix[i][0] = 0; - } - } } + + static void setZeroesInCols(int[][] matrix, int rows, int cols) { + for (int j = 1; j < cols; j++) { + if (matrix[0][j] == 0) { + for (int i = 1; i < rows; i++) { + matrix[i][j] = 0; + } + } + } + } + + static void setZeroesInFirstRow(int[][] matrix, int cols) { + for (int j = 0; j < cols; j++) { + matrix[0][j] = 0; + } + } + + static void setZeroesInFirstCol(int[][] matrix, int rows) { + for (int i = 0; i < rows; i++) { + matrix[i][0] = 0; + } + } + + static void setZeroesByOptimalApproach(int[][] matrix) { + int rows = matrix.length; + int cols = matrix[0].length; + + boolean firstRowZero = hasZeroInFirstRow(matrix, cols); + boolean firstColZero = hasZeroInFirstCol(matrix, rows); + + markZeroesInMatrix(matrix, rows, cols); + + setZeroesInRows(matrix, rows, cols); + setZeroesInCols(matrix, rows, cols); + + if (firstRowZero) { + setZeroesInFirstRow(matrix, cols); + } + if (firstColZero) { + setZeroesInFirstCol(matrix, rows); + } + } + }