leetcode

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

commit e117352fca8c59577017bf8b4a9a1baf0e8386f7
parent d1a29b04a40e7bb92438c36a1f5388ba506e182d
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Fri, 22 Dec 2023 15:35:25 +0000

Daily Problem

Diffstat:
AProblems/1422.cpp | 14++++++++++++++
MREADME.md | 1+
2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/Problems/1422.cpp b/Problems/1422.cpp @@ -0,0 +1,14 @@ +class Solution { + public: + int maxScore(const string &s) const { + int res = 0, zero = 0, one = count(begin(s), end(s), '1'); + for (int i = 0; i < size(s) - 1; i++) { + if (s[i] == '1') + one--; + else + zero++; + res = max(res, zero + one); + } + return res; + } +}; diff --git a/README.md b/README.md @@ -699,6 +699,7 @@ for solving problems. | 1416 | Hard | [Restore The Array](Problems/1416.cpp) | | 1418 | Medium | [Display Table of Food Orders in a Restaurant](Problems/1418.cpp) | | 1420 | Hard | [Build Array Where You Can Find The Maximum Exactly K Comparisons](Problems/1420.cpp) | +| 1422 | Easy | [Maximum Score After Splitting a String](Problems/1422.cpp) | | 1424 | Medium | [Diagonal Traverse II](Problems/1424.cpp) | | 1425 | Hard | [Constrained Subsequence Sum](Problems/1425.cpp) | | 1431 | Easy | [Kids With the Greatest Number of Candies](Problems/1431.cpp) |