LeetCode/cs/make-the-string-great.cs
Matej Focko 04ecc74e91
cs: add «1544. Make The String Great»
Signed-off-by: Matej Focko <mfocko@redhat.com>
2024-04-05 18:10:34 +02:00

21 lines
501 B
C#

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());
}
}