leetcode

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

commit ccdc06381d6b8aed72122ef14d92cbb0b21e908b
parent 0915a63bbe73399437f5c15262a4a1847378ade8
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Fri, 12 Jul 2024 15:45:04 +0200

Daily Problem

Diffstat:
AProblems/1717.cpp | 28++++++++++++++++++++++++++++
MREADME.md | 1+
2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/Problems/1717.cpp b/Problems/1717.cpp @@ -0,0 +1,28 @@ +class Solution { + public: + int maximumGain(const string s, int x, int y) const { + int res = 0, a = 0, b = 0, mini = min(x, y); + + for (const char c : s) { + if (c > 'b') { + res += min(a, b) * mini; + a = b = 0; + continue; + } + + if (c == 'a') { + if (x < y && b > 0) + b--, res += y; + else + a++; + } else { + if (x > y && a > 0) + a--, res += x; + else + b++; + } + } + + return res + min(a, b) * mini; + } +}; diff --git a/README.md b/README.md @@ -943,6 +943,7 @@ for solving problems. | 1704 | Easy | [Determine if String Halves Are Alike](Problems/1704.cpp) | | 1706 | Medium | [Where Will the Ball Fall](Problems/1706.cpp) | | 1716 | Easy | [Calculate Money in Leetcode Bank](Problems/1716.cpp) | +| 1717 | Medium | [Maximum Score From Removing Substrings](Problems/1717.cpp) | | 1718 | Medium | [Construct the Lexicographically Largest Valid Sequence](Problems/1718.cpp) | | 1721 | Medium | [Swapping Nodes in a Linked List](Problems/1721.cpp) | | 1722 | Medium | [Minimize Hamming Distance After Swap Operations](Problems/1722.cpp) |