cs: add «1422. Maximum Score After Splitting a String»

URL:	https://leetcode.com/problems/maximum-score-after-splitting-a-string/
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2025-01-01 12:48:45 +01:00
parent 4e0f9fbca5
commit ec2d7fe842
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

View file

@ -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;
}
}