mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-10 00:09:06 +01:00
22 lines
501 B
C#
22 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());
|
||
|
}
|
||
|
}
|