commit cb6d5d987ae031541fd1b411751994b66470030b parent b18549f3fc14b71d6273ecda36cad69f9ce781cb Author: Dimitrije Dobrota <mail@dimitrijedobrota.com> Date: Tue, 30 Jul 2024 20:49:03 +0200 1 Random Problem Diffstat:
A | Problems/3228.cpp | | | 20 | ++++++++++++++++++++ |
M | README.md | | | 1 | + |
2 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/Problems/3228.cpp b/Problems/3228.cpp @@ -0,0 +1,20 @@ +class Solution { + public: + int maxOperations(const string &s) const { + const int n = size(s); + int res = 0, count = 0; + + for (int i = 0; i < n;) { + const int start = i; + + while (i < n && s[i] == s[start]) + i++; + + if (s[start] == '0') + res += count; + else + count += i - start; + } + return res; + } +}; diff --git a/README.md b/README.md @@ -1303,3 +1303,4 @@ for solving problems. | 3195 | Medium | [Find the Minimum Area to Cover All Ones I](Problems/3195.cpp) | | 3211 | Medium | [Generate Binary Strings Without Adjacent Zeros](Problems/3211.cpp) | | 3212 | Medium | [Count Submatrices With Equal Frequency of X and Y](Problems/3212.cpp) | +| 3228 | Medium | [Maximum Number of Operations to Move Ones to the End](Problems/3228.cpp) |