string BrokenBackSpace(string s) {
Stack<char> outStack = new Stack<char>();
string output = "";
for(int i = 0; i < s.Length; i++)
{
if (s[i] != '#')
{
outStack.Push(s[i]);
}
else
{
if (outStack.Count > 0)
outStack.Pop();
}
}
while(outStack.Count > 0)
output += outStack.Pop();
for (int i = 0; i < output.Length; i++)
outStack.Push(output[i]);
output = "";
while(outStack.Count > 0)
output += outStack.Pop();
return output;
}
Editor is loading...