Skip to content

Commit

Permalink
solution(java): 73. Set Matrix Zeroes
Browse files Browse the repository at this point in the history
  • Loading branch information
godkingjay authored Oct 9, 2023
2 parents 58ccd49 + 63d2eb0 commit 6ded25b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Easy/0073. Set Matrix Zeroes/0073-set-matrix-zeroes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution {
public void setZeroes(int[][] matrix) {
int rows = matrix.length, cols = matrix[0].length;
boolean colu=true;

for (int i = 0; i < rows; i++) {
if (matrix[i][0] == 0) colu = false;
for (int j = 1; j < cols; j++){
if (matrix[i][j] == 0){
matrix[i][0] = matrix[0][j] = 0;
}
}
}

for (int i = rows - 1; i >= 0; i--) {
for (int j = cols - 1; j >= 1; j--){
if (matrix[i][0] == 0 || matrix[0][j] == 0){
matrix[i][j] = 0;
}
}
if (colu == false) matrix[i][0] = 0;
}
}
}

0 comments on commit 6ded25b

Please sign in to comment.