1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-19 01:36:57 +02:00

cs: add «1544. Make The String Great»

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2024-04-05 18:10:34 +02:00
parent 2c5ebe699d
commit 04ecc74e91
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -0,0 +1,21 @@
public class Solution {
public string MakeGood(string s) {
var st = new List<char>();
foreach (char c in s) {
var idx = st.Count - 1;
if (
idx < 0
|| Char.ToLower(c) != Char.ToLower(st[idx])
|| Char.IsUpper(c) == Char.IsUpper(st[idx])
) {
st.Add(c);
} else {
st.RemoveAt(idx);
}
}
return new string(st.ToArray());
}
}