public class Solution
    {
        public void SetZeroes(int[,] matrix)
        {
            var row = matrix.GetLength(0);
            var col = matrix.GetLength(1);
            var listrow = new Dictionary<int, int>();
            var listcol = new Dictionary<int, int>();
            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    if (matrix[i, j] == 0)
                    {
                        if (!listrow.ContainsKey(i))
                        {
                            listrow.Add(i, 0);
                        }
                        if (!listcol.ContainsKey(j))
                        {
                            listcol.Add(j, 0);
                        }
                    }
                }
            }
            foreach (var l in listrow)
            {
                for (int j = 0; j < col; j++)
                {
                    matrix[l.Key, j] = 0;
                }
            }
            foreach (var l in listcol)
            {
                for (int i = 0; i < row; i++)
                {
                    matrix[i, l.Key] = 0;
                }
            }
        }
    }

 

posted on 2018-10-05 20:52  Sempron2800+  阅读(134)  评论(0编辑  收藏  举报