leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0073.cpp (644B)
0 class Solution { 1 public: 2 void setZeroes(vector<vector<int>> &matrix) { 3 int n = matrix.size(), m = matrix[0].size(); 4 unordered_set<int> rows, cols; 5 6 for (int i = 0; i < n; i++) { 7 for (int j = 0; j < m; j++) { 8 if (matrix[i][j]) continue; 9 rows.insert(i); 10 cols.insert(j); 11 } 12 } 13 14 for (int row : rows) { 15 for (int j = 0; j < m; j++) 16 matrix[row][j] = 0; 17 } 18 19 for (int col : cols) { 20 for (int i = 0; i < n; i++) 21 matrix[i][col] = 0; 22 } 23 24 return; 25 } 26 };