cs: add «1544. Make The String Great»
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
2c5ebe699d
commit
04ecc74e91
1 changed files with 21 additions and 0 deletions
21
cs/make-the-string-great.cs
Normal file
21
cs/make-the-string-great.cs
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue