Apply formatting

This commit is contained in:
anujgaud 2024-03-16 23:49:41 +05:30 committed by GitHub
parent 576925e862
commit 9d0024b926
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 0 deletions

View File

@ -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;