From 04ecc74e91033cb829ea3bdb250175cc8dcfbf69 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Fri, 5 Apr 2024 18:10:34 +0200 Subject: [PATCH] =?UTF-8?q?cs:=20add=20=C2=AB1544.=20Make=20The=20String?= =?UTF-8?q?=20Great=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej Focko --- cs/make-the-string-great.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 cs/make-the-string-great.cs diff --git a/cs/make-the-string-great.cs b/cs/make-the-string-great.cs new file mode 100644 index 0000000..8f76e91 --- /dev/null +++ b/cs/make-the-string-great.cs @@ -0,0 +1,21 @@ +public class Solution { + public string MakeGood(string s) { + var st = new List(); + + 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()); + } +}