Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.
public class Solution {
public void setZeroes(int[][] matrix) {
int m = matrix.length,n = matrix[0].length;
int k = 0;
int[][] mark = new int[1000][2];
for(int i=0;i<1000;i++)
for(int j=0;j<2;j++)
mark[i][j] = -1;
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
{
if(matrix[i][j]==0)
{
mark[k][0] = i;
mark[k][1] = j;
k++;
}
}
for(int i=0;i<1000;i++)
{
if(mark[i][0]!=-1)
Zeroes(matrix,mark[i][0],mark[i][1]);
}
}
public void Zeroes(int[][] a,int row,int col)
{
int m = a.length,n = a[0].length;
for(int i=0;i<n;i++)
{
a[row][i] = 0;
}
for(int j=0;j<m;j++)
{
a[j][col] = 0;
}
}
}