diff --git a/LeetCode/Set_Matrix_Zero.cpp b/LeetCode/Set_Matrix_Zero.cpp new file mode 100644 index 0000000..22e473c --- /dev/null +++ b/LeetCode/Set_Matrix_Zero.cpp @@ -0,0 +1,22 @@ +class Solution { +public: + void setZeroes(vector>& matrix) { + set rows; + set cols; + for(int i = 0; i < matrix.size(); i++) + for(int j = 0; j < matrix[0].size();j++) + if(matrix[i][j] == 0) { + rows.insert(i); + cols.insert(j); + } + + for(auto x: rows) + for(int j = 0; j < matrix[0].size();j++) + matrix[x][j] = 0; + + for(auto x: cols) + for(int i = 0; i < matrix.size(); i++) + matrix[i][x] = 0; + + } +}; \ No newline at end of file