public class Solution { public void SetZeroes(int[,] matrix) { var row = matrix.GetLength(0); var col = matrix.GetLength(1); if(row <= 1 && col <= 1){ return; } var q = new Queue(); for(var i = 0;i < row; i++){ for(var j = 0;j < col; j++){ if(matrix[i,j] == 0){ q.Enqueue(new Pos(i,j)); } } } while(q.Count > 0){ var pos = q.Dequeue(); for(var i = pos.row;i >=0; i--){ matrix[i,pos.col] = 0; } for(var i = pos.row;i < row; i++){ matrix[i,pos.col] = 0; } for(var i = pos.col;i >=0; i--){ matrix[pos.row,i] = 0; } for(var i = pos.col;i < col; i++){ matrix[pos.row,i] = 0; } } } public class Pos{ public Pos(int r, int c) { row = r; col = c; } public int row; public int col; } }