leetcode

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

commit 7d073950148ac9a6b3ffb747d31ea2ef13a6f361
parent 53bb1f937d3a913ec83528296036ff2a1381f2fa
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Thu,  1 Feb 2024 22:08:38 +0000

1 Random Problem

Diffstat:
AProblems/0554.cpp | 19+++++++++++++++++++
MREADME.md | 1+
2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/Problems/0554.cpp b/Problems/0554.cpp @@ -0,0 +1,19 @@ +class Solution { + public: + int leastBricks(const vector<vector<int>> &wall) const { + const int n = size(wall); + unordered_map<int, int> count; + + for (const auto &row : wall) { + long long crnt = 0; + for (int i = 0; i < size(row) - 1; i++) { + count[crnt += row[i]]++; + } + } + + int res = 0; + for (const auto [_, v] : count) + res = max(res, v); + return n - res; + } +}; diff --git a/README.md b/README.md @@ -372,6 +372,7 @@ for solving problems. | 0547 | Medium | [Number of Provinces](Problems/0547.cpp) | | 0550 | Medium | [Game Play Analysis IV](Problems/0550.cpp) | | 0553 | Medium | [Optimal Division](Problems/0553.cpp) | +| 0554 | Medium | [Brick Wall](Problems/0554.cpp) | | 0556 | Medium | [Next Greater Element III](Problems/0556.cpp) | | 0557 | Easy | [Reverse Words in a String III](Problems/0557.cpp) | | 0559 | Easy | [Maximum Depth of N-ary Tree](Problems/0559.cpp) |