From ec2d7fe84201bbc1d65b18e48946cf75fda0e31b Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Wed, 1 Jan 2025 12:48:45 +0100 Subject: [PATCH] =?UTF-8?q?cs:=20add=20=C2=AB1422.=20Maximum=20Score=20Aft?= =?UTF-8?q?er=20Splitting=20a=20String=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit URL: https://leetcode.com/problems/maximum-score-after-splitting-a-string/ Signed-off-by: Matej Focko --- cs/maximum-score-after-splitting-a-string.cs | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 cs/maximum-score-after-splitting-a-string.cs diff --git a/cs/maximum-score-after-splitting-a-string.cs b/cs/maximum-score-after-splitting-a-string.cs new file mode 100644 index 0000000..89ea541 --- /dev/null +++ b/cs/maximum-score-after-splitting-a-string.cs @@ -0,0 +1,22 @@ +public class Solution { + public int MaxScore(string s) { + var ones = s.Skip(1).Count(c => c == '1'); + var zeros = s.Take(1).Count(c => c == '0'); + + var foundScore = ones + zeros; + for (var i = 1; i < s.Length - 1; ++i) { + switch (s[i]) { + case '0': + ++zeros; + break; + case '1': + --ones; + break; + } + + foundScore = Math.Max(foundScore, ones + zeros); + } + + return foundScore; + } +}