Skip to content

Instantly share code, notes, and snippets.

@Ray1988
Created June 4, 2014 05:47
Show Gist options
  • Save Ray1988/47709b16dfc83a04d27f to your computer and use it in GitHub Desktop.
Save Ray1988/47709b16dfc83a04d27f to your computer and use it in GitHub Desktop.
Java
public class Solution {
public void setZeroes(int[][] matrix) {
if (matrix==null||matrix.length==0){
return;
}
boolean[] rows=new boolean[matrix.length];
boolean[] cols=new boolean[matrix[0].length];
for (int row=0; row<matrix.length; row++){
for (int col=0; col<matrix[0].length; col++){
if (matrix[row][col]==0){
rows[row]=true;
cols[col]=true;
}
}
}
for (int i=0; i<matrix.length; i++){
for (int j=0; j<matrix[0].length; j++){
if (rows[i]||cols[j]){
matrix[i][j]=0;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment