Apply formatting
This commit is contained in:
parent
576925e862
commit
9d0024b926
@ -33,6 +33,7 @@ public class SetMatrixToZero{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setZeroesExtraSpace(int[][] matrix) {
|
static void setZeroesExtraSpace(int[][] matrix) {
|
||||||
int rows = matrix.length;
|
int rows = matrix.length;
|
||||||
int cols = matrix[0].length;
|
int cols = matrix[0].length;
|
||||||
@ -48,17 +49,20 @@ public class SetMatrixToZero{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int row: rowSet){
|
for(int row: rowSet){
|
||||||
for(int j = 0; j < cols; j++){
|
for(int j = 0; j < cols; j++){
|
||||||
matrix[row][j] = 0;
|
matrix[row][j] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int col: colSet) {
|
for(int col: colSet) {
|
||||||
for(int i = 0; i < rows; i++){
|
for(int i = 0; i < rows; i++){
|
||||||
matrix[i][col] = 0;
|
matrix[i][col] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setZeroesOptimized(int[][] matrix){
|
static void setZeroesOptimized(int[][] matrix){
|
||||||
int rows = matrix.length;
|
int rows = matrix.length;
|
||||||
int cols = matrix[0].length;
|
int cols = matrix[0].length;
|
||||||
@ -79,6 +83,7 @@ public class SetMatrixToZero{
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 1; i < rows; i++){
|
for(int i = 1; i < rows; i++){
|
||||||
for(int j = 1; j < cols; j++){
|
for(int j = 1; j < cols; j++){
|
||||||
if (matrix[i][j] == 0){
|
if (matrix[i][j] == 0){
|
||||||
@ -87,6 +92,7 @@ public class SetMatrixToZero{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 1; i < rows; i++){
|
for(int i = 1; i < rows; i++){
|
||||||
if(matrix[i][0] == 0){
|
if(matrix[i][0] == 0){
|
||||||
for(int j = 1; j < cols; j++){
|
for(int j = 1; j < cols; j++){
|
||||||
@ -94,6 +100,7 @@ public class SetMatrixToZero{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int j = 1; j < cols; j++){
|
for(int j = 1; j < cols; j++){
|
||||||
if(matrix[0][j] == 0) {
|
if(matrix[0][j] == 0) {
|
||||||
for(int i = 1; i < rows; i++){
|
for(int i = 1; i < rows; i++){
|
||||||
@ -101,11 +108,13 @@ public class SetMatrixToZero{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(firstRowZero){
|
if(firstRowZero){
|
||||||
for(int j = 0; j < cols; j++){
|
for(int j = 0; j < cols; j++){
|
||||||
matrix[0][j] = 0;
|
matrix[0][j] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(firstColZero){
|
if(firstColZero){
|
||||||
for(int i = 0; i < rows; i++){
|
for(int i = 0; i < rows; i++){
|
||||||
matrix[i][0] = 0;
|
matrix[i][0] = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user