标签:int col tor cto color bsp nbsp matrix +=
1 class Solution 2 { 3 int dx[4] = {1,0,-1,0}; 4 int dy[4] = {0,1,0,-1}; 5 public: 6 void setZeroes(vector<vector<int>>& matrix) 7 { 8 int m = matrix.size(),n = matrix[0].size(); 9 vector<vector<bool>> flag(m,vector<bool>(n,false)); 10 11 for(int i = 0;i < m;i ++)//首先标记哪些元素为0 12 { 13 for(int j = 0;j < n;j ++) 14 { 15 if(matrix[i][j] == 0) flag[i][j] = true; 16 } 17 } 18 19 for(int i = 0;i < m;i ++) 20 { 21 for(int j = 0;j < n;j ++) 22 { 23 if(flag[i][j]) //标记的元素如果为True,就可以进行修改 24 { 25 for(int k = 0;k < 4;k ++) 26 { 27 int x = dx[k] + i,y = dy[k] + j; 28 while(x >= 0 && x < m && y >= 0 && y < n)//一直朝着某个方向修改 29 { 30 matrix[x][y] = 0; 31 x += dx[k]; 32 y += dy[k]; 33 } 34 } 35 } 36 } 37 } 38 } 39 };
标签:int col tor cto color bsp nbsp matrix +=
原文地址:https://www.cnblogs.com/yuhong1103/p/12600273.html