leetcode

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

commit 9e61935bb3d8aac3946e9113463b124850721305
parent de5b50c4f9389c84a4e30d07a99e4338741867c8
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Mon,  7 Oct 2024 21:28:22 +0200

Daily Problem

Diffstat:
AProblems/2696.cpp | 22++++++++++++++++++++++
MREADME.md | 1+
2 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/Problems/2696.cpp b/Problems/2696.cpp @@ -0,0 +1,22 @@ +class Solution { + public: + int minLength(string s) const { + int n = size(s); + while (true) { + int j = 0; + for (int i = 0; i < n; i++) { + if (s[i] == 'A' && s[i + 1] == 'B') + i++; + else if (s[i] == 'C' && s[i + 1] == 'D') + i++; + else + s[j++] = s[i]; + } + + if (j == n) break; + s[n = j] = '\0'; + } + + return n; + } +}; diff --git a/README.md b/README.md @@ -1298,6 +1298,7 @@ for solving problems. | 2679 | Medium | [Sum in a Matrix](Problems/2679.cpp) | | 2683 | Medium | [Neighboring Bitwise XOR](Problems/2683.cpp) | | 2685 | Medium | [Count the Number of Complete Components](Problems/2685.cpp) | +| 2696 | Easy | [Minimum String Length After Removing Substrings](Problems/2696.cpp) | | 2698 | Medium | [Find the Punishment Number of an Integer](Problems/2698.cpp) | | 2699 | Hard | [Modify Graph Edge Weights](Problems/2699.cpp) | | 2706 | Easy | [Buy Two Chocolates](Problems/2706.cpp) |