From 77b300b36cf14568b453c2cad49d77cf7cc44fec Mon Sep 17 00:00:00 2001 From: attttt17 <57448162+attttt17@users.noreply.github.com> Date: Sun, 2 Oct 2022 21:51:52 +0530 Subject: [PATCH] Add files via upload --- LeetCode/Set_Matrix_Zero.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 LeetCode/Set_Matrix_Zero.cpp 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