leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit 3435beb8a91a4268a04a1a21b8df67cba35a3ff8
parent 8561c37ee0c619ca1b21fbce159c647ae2739b2d
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Wed, 12 Apr 2023 16:51:54 +0200

Random Problem

Diffstat:
AProblems/0073.cpp | 25+++++++++++++++++++++++++
MREADME.md | 1+
2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/Problems/0073.cpp b/Problems/0073.cpp @@ -0,0 +1,25 @@ +class Solution { +public: + void setZeroes(vector<vector<int>> &matrix) { + int n = matrix.size(), m = matrix[0].size(); + unordered_set<int> rows, cols; + + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (matrix[i][j]) continue; + rows.insert(i); + cols.insert(j); + } + } + + for (int row : rows) { + for (int j = 0; j < m; j++) matrix[row][j] = 0; + } + + for (int col : cols) { + for (int i = 0; i < n; i++) matrix[i][col] = 0; + } + + return; + } +}; diff --git a/README.md b/README.md @@ -90,6 +90,7 @@ for solving problems. | 0070 | Easy | [Climbing Stairs](Problems/0070.cpp) | | 0071 | Medium | [Simplify Path](Problems/0071.cpp) | | 0072 | Hard | [Edit Distance](Problems/0072.cpp) | +| 0073 | Medium | [Set Matrix Zeroes](Problems/0073.cpp) | | 0074 | Medium | [Search a 2D Matrix](Problems/0074.cpp) | | 0075 | Medium | [Sort Colors](Problems/0075.cpp) | | 0076 | Hard | [Minimum Window Substring](Problems/0076.cpp) |