Created
June 18, 2014 00:20
-
-
Save iwilbert/9a6463330ddf8ac34b61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void zero(int[][] matrix) { | |
if(matrix == null) | |
return; | |
int m = matrix.length; | |
if(m == 0) | |
return; | |
int n = matrix[0].length; | |
boolean[] row_zero = new boolean[m]; | |
boolean[] col_zero = new boolean[n]; | |
for(int i = 0; i < m; i++) | |
for(int j = 0; j < n; j++) | |
{ | |
if(matrix[i][j] == 0) | |
{ | |
row_zero[i] = true; | |
col_zero[j] = true; | |
} | |
} | |
for(int i = 0; i < m; i++) | |
for(int j = 0; j < n; j++) | |
{ | |
if(row_zero[i] || col_zero[j]) | |
matrix[i][j] = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment